我正在尝试使用多行和stat_summary来定义平均值。当我应用geom_errorbar()时,它们中的一些被放置在距离平均迹象一定距离处,这意味着其中一些是“飞行”的。发生什么事?错误位置错误
谢谢!
我的代码:
#First I add another data set with SE, SD and mean.
cdata <- ddply(data2, c("OGTT","Treatment"), summarise,
N = sum(!is.na(Glucose)),
mean = mean(Glucose, na.rm=TRUE),
sd = sd(Glucose, na.rm=TRUE),
se = sd/sqrt(N))
#Then I merge it with my original data
totalglu<-merge(data2,cdata)
#Then I make the ggplot
p<-ggplot(data=totalglu, aes(x = factor(OGTT), y = Glucose, 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) +
theme(legend.position="none") +
labs(x = "OGTT time points (min)",y= "Glucose (mmol/l)")+
geom_errorbar(aes(ymin=mean-se,ymax=mean+se), width=.1, colour="black")
p
My plot with flying errorbars for a some of the points
有什么理由不使用'mean_cl_normal'使一次性代替均值和CI?另外:你能发布导致问题的数据吗(也就是说,我没有'data2',所以不能绘制你的图)。 –
对不起,我之前错过了这一点:看起来,错误栏位于网格的顶部和底部行中的相同位置。最有可能的原因是在'stat_summary'和'geom_errorbar'(或在ddply调用)中,facet的工作方式不同 –