I'm using the following code:
library (ggplot2)
df=data.frame(score=c(1,3,5,9,7,8,4,1,2,6,1,6,2,1,3,1,3,5,8,4),
age=c(2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3))
ggplot(data=df,aes(x=age,y=score))+
geom_point(position=position_jitter(width=.1),aes(color=age))+
geom_line(stat = "hline", yintercept = "mean",aes(group=age))+
stat_summary(geom = "line", fun.y="mean",aes(yend=..y..),width=.5)+
stat_summary(fun.data="mean_cl_boot",geom="errorbar",width=.5)+
theme_classic()
But I get this error:
Error: Found object is not a stat.
Does anyone know how to solve this problem? I used this before but now it's not working.I want to produce something like this:
I would like to have the mean bar but I could only produce something like this:
You can achieve the same result using stat_summary
with the errorbar geom and setting ymin
and ymax
to be the summary statistic via the special variable ..y..
.
ggplot(df, aes(x = age, y = score)) +
geom_point(position = position_jitter(width = .2), aes(color = age)) +
stat_summary(fun.data = "mean_cl_boot", geom = "errorbar", width = .5) +
stat_summary(geom = "errorbar", fun.y = mean, aes(ymin = ..y.., ymax = ..y..))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.