r语言 - 将误差线应用于 ggplot 中的平均值



我已经为两种不同的治疗方法制作了不同时间点(OGTT)的胰岛素浓度的ggplot。之后,我添加了显示平均值的点:

p<-ggplot(data=data2, aes(x = factor(OGTT), y = Insulin, group = StudyID, color=StudyID)) + 
  geom_line() +
  facet_grid(End.start ~Treatment)+ 
  stat_summary(aes(group = Treatment), geom = "point", fun.y = mean, shape = 16, size = 2) 

我的问题是:

  1. 如何在平均值点上添加误差线?
  2. 如何避免剧情出现任何传说?

ggplot2 cookbook 有像这样的大多数相当基本问题的答案。

要添加误差线,请分别计算误差线的上限和下限值。然后使用geom_errorbar()绘制。

http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/

要删除所有图例,请使用

theme(legend.position="none")

为了获得更多控制,还有许多其他选项。

http://www.cookbook-r.com/Graphs/Legends_(ggplot2)/

最新更新