我使用ggplot2创建了一个boxplot:
library(ggplot2)
dat <- data.frame(study = c(rep('a',50),rep('b',50)),
FPKM = c(rnorm(1:50),rnorm(1:50)))
ggplot(dat, aes(x = study, y = FPKM)) + geom_boxplot()
Run Code Online (Sandbox Code Playgroud)
箱线图将中位数显示为每个方框的水平线.
如何在表示该组平均值的框中添加虚线?
谢谢!
aos*_*ith 20
您可以使用stat_summarywith 将水平线添加到绘图中geom_errorbar.该线是水平的,因为y最小值和最大值设置为与y相同.
ggplot(dat, aes(x = study, y = FPKM)) +
geom_boxplot() +
stat_summary(fun.y = mean, geom = "errorbar", aes(ymax = ..y.., ymin = ..y..),
width = .75, linetype = "dashed")
Run Code Online (Sandbox Code Playgroud)