[英]R ggplot2: Add means as horizontal line in a boxplot
我使用 ggplot2 創建了一個箱線圖:
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()
箱線圖將中位數顯示為跨越每個框的水平線。
如何在表示該組平均值的框中添加虛線?
謝謝!
您可以通過將stat_summary與geom_errorbar一起使用來向繪圖添加水平線。 該線是水平的,因為 y 的最小值和最大值設置為與 y 相同。
stat_summary
geom_errorbar
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")
[英]Joining means on a boxplot with a line (ggplot2)
[英]Add horizontal rectangle to categorical boxplot in ggplot2
[英]How to add a line to a boxplot using ggplot2
[英]R manual boxplot with means and standard deviations (ggplot2)
[英]R ggplot2 geom_boxplot horizontal bars
[英]R with ggplot2 horizontal line for average
[英]Add a horizontal line to plot and legend in ggplot2
[英]How to add horizontal lines showing means for all groups in ggplot2?
[英]Boxplot in R using ggplot2
[英]grouped boxplot r ggplot2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.