我正在尝试为我的数据添加标准错误栏,类似于在这个问题的答案末尾附近的方框图上看到的:https://stats.stackexchange.com/questions/8137/how-to-add -水平线到GGPLOT2-箱线图
我正在使用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
Run Code Online (Sandbox Code Playgroud)
我制作了这个情节
使用以下代码
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
Run Code Online (Sandbox Code Playgroud)
我不知道如何根据该因子变量内的变化为每个绘图添加一个误差条.我添加+geom_errorbar(aes(x=group, ymin=mean-sd, ymax=mean+sd))但它返回错误"错误的意思 - sd:非数字参数到二元运算符"
任何帮助,将不胜感激.谢谢
sha*_*yaa 10
mean_seggplot2中有一个功能可以完全满足您的需求.
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")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11647 次 |
| 最近记录: |