你好,我想在我的图中添加错误栏,
但它添加了多个单色错误栏。 我只想为 4 个数据点中的每一个添加误差条。
Normal plot without errorbars function
The plot after I added geom_errorbar
Sex=as.factor(dromedar$sex)
Posture=as.factor(dromedar$posture)
item= dromedar$itemValue
sd_item= sd(item)
carePlot<-(ggplot() + aes(x = Posture, color = Sex, group = Sex, y = item) +
stat_summary(fun.y = mean, geom = "point") +
stat_summary(fun.y = mean, geom = "line") +
coord_cartesian(ylim = c(0.5, 7.5)) +
#Following line makes the difference between the plots
geom_errorbar(aes(ymin=item-sd_item, ymax=item+sd_item), width=.2) +
labs(title = "Medical Leader", x="Physician's posture") +
ylab("Medical Leader ratings") +
scale_y_continuous(breaks=seq(0,8,1))+
scale_color_discrete(name = "Sex of physician", labels = c("female physician", "male physician"))
)
carePlot