我正在尝试向我的数据添加标准误差线,类似于在该问题答案的结尾附近的方框图中看到的误差线:https : //stats.stackexchange.com/questions/8137/how-to-add水平线到ggplot2-boxplot
我正在使用PlantGrowth数据集,它看起来像这样(除了总共30行长):
weight group
1 4.17 ctrl
2 5.58 ctrl
3 4.81 trt1
4 4.17 trt1
5 6.31 trt2
6 5.12 trt2
我已经制作了这个情节
用下面的代码
ggplot(PlantGrowth, aes(group, weight))+
stat_boxplot(geom='errorbar', linetype=1, width=0.5)+ #whiskers
geom_boxplot(outlier.shape=1)+
stat_summary(fun.y=mean, geom="point", size=2) #dot for the mean
我不知道如何基于该因子变量中的变化为每个图添加误差线。我已经添加了,+geom_errorbar(aes(x=group, ymin=mean-sd, ymax=mean+sd))
但是它返回错误“均值错误-sd:二进制运算符的非数字参数”
任何帮助,将不胜感激。谢谢
mean_se
ggplot2中有一个功能完全可以满足您的需求。
library(ggplot2)
ggplot(PlantGrowth, aes(group, weight))+
stat_boxplot( aes(group, weight),
geom='errorbar', linetype=1, width=0.5)+ #whiskers
geom_boxplot( aes(group, weight),outlier.shape=1) +
stat_summary(fun.y=mean, geom="point", size=2) +
stat_summary(fun.data = mean_se, geom = "errorbar")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句