其他
你一半我一半的gghalves
💡专注R语言在🩺生物医学中的使用
安装
# 2选1
install.packages("gghalves")
devtools::install_github('erocoar/gghalves')
使用
主要是添加了3种half geoms
:boxplot,violin,point
geomhalfpoint
library(gghalves)
## Loading required package: ggplot2
ggplot(iris, aes(Species, Sepal.Width)) +
geom_half_point()
ggplot(iris, aes(x = Species, y = Sepal.Width)) +
geom_half_point(transformation = PositionIdentity)
geom_half_point_panel
ggplot(iris, aes(y = Sepal.Width)) +
geom_half_boxplot() +
geom_half_point_panel(aes(x = 0.5, color = Species), range_scale = .5)
geomhalfboxplot
ggplot(iris, aes(x = Species, y = Sepal.Width)) +
geom_half_boxplot()
ggplot(iris, aes(x = Species, y = Sepal.Width)) +
geom_half_boxplot(side = "r", center = TRUE, errorbar.draw = FALSE)
geomhalfviolin
ggplot(iris, aes(x = Species, y = Sepal.Width)) +
geom_half_violin()
ggplot() +
geom_half_violin(
data = ToothGrowth,
aes(x = as.factor(dose), y = len, split = supp, fill = supp),
position = "identity"
)
geomhalfdotplot
ggplot(iris, aes(x = Species, y = Sepal.Width)) +
geom_half_violin() +
geom_dotplot(binaxis = "y", method="histodot", stackdir="up")
## Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.
df <- data.frame(score = rgamma(150, 4, 1),
gender = sample(c("M", "F"), 150, replace = TRUE),
genotype = factor(sample(1:3, 150, replace = TRUE)))
ggplot(df, aes(x = genotype, y = score, fill = gender)) +
geom_half_violin() +
geom_dotplot(binaxis = "y", method="histodot", stackdir="up", position = PositionDodge)
## Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.
ggplot(df, aes(x = genotype, y = score, fill = gender)) +
geom_half_violin() +
geom_half_dotplot(method="histodot", stackdir="up")
## Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.
自由组合
suppressPackageStartupMessages(library(tidyverse))
ggplot() +
geom_half_boxplot(
data = iris %>% filter(Species=="setosa"),
aes(x = Species, y = Sepal.Length, fill = Species), outlier.color = NA) +
ggbeeswarm::geom_beeswarm(
data = iris %>% filter(Species=="setosa"),
aes(x = Species, y = Sepal.Length, fill = Species, color = Species), beeswarmArgs=list(side=+1)
) +
geom_half_violin(
data = iris %>% filter(Species=="versicolor"),
aes(x = Species, y = Sepal.Length, fill = Species), side="r") +
geom_half_dotplot(
data = iris %>% filter(Species=="versicolor"),
aes(x = Species, y = Sepal.Length, fill = Species), method="histodot", stackdir="down") +
geom_half_boxplot(
data = iris %>% filter(Species=="virginica"),
aes(x = Species, y = Sepal.Length, fill = Species), side = "r", errorbar.draw = TRUE,
outlier.color = NA) +
geom_half_point(
data = iris %>% filter(Species=="virginica"),
aes(x = Species, y = Sepal.Length, fill = Species, color = Species), side = "l") +
scale_fill_manual(values = c("setosa" = "#cba1d2", "versicolor"="#7067CF","virginica"="#B7C0EE")) +
scale_color_manual(values = c("setosa" = "#cba1d2", "versicolor"="#7067CF","virginica"="#B7C0EE")) +
theme(legend.position = "none")
## Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.
获取更多信息,欢迎加入🐧QQ交流群:613637742
“医学和生信笔记,专注R语言在临床医学中的使用、R语言数据分析和可视化。主要分享R语言做医学统计学、meta分析、网络药理学、临床预测模型、机器学习、生物信息学等。
往期回顾
R语言机器学习R包:mlr3(合辑)
R语言和医学统计学(合辑)
使用R语言画森林图和误差线(合辑)
ggplot2可视化拷贝数变异CNV的GISTIC score
初学者使用R语言读取、写出文件(csv/txt/excel/rdata等)的注意事项
又是聚类分析可视化!