summarySE=function(data=NULL,measurevar,groupvars=NULL,na.rm=FALSE,conf.interval=.95, .drop=TRUE){
library(plyr)
length2=function(x,na.rm=FALSE){
if(na.rm)sum(!is.na(x))
else length(x)
}
datac=ddply(data,groupvars,.drop=.drop,.fun=function(xx,col,na.rm){
c(n=length2(xx[,col],na.rm=na.rm),
mean=mean(xx[,col],na.rm=na.rm),
sd=sd(xx[,col],na.rm=na.rm))
},
measurevar,
na.rm)
datac <-rename(datac,c("mean" =measurevar))
datac$se <-datac$sd /sqrt(datac$n)
ciMult <-qt(conf.interval/2 + .5,datac$n-1)
datac$ci <-datac$se *ciMult
return(datac)
}
> sm=summarySE(data,measurevar="height",groupvars=c("DAS","treatment"))
> smp=ggplot(sm,aes(x=DAS,y=height,colour=treatment))
> p+geom_errorbar(aes(ymin=height-se,ymax=height+se),width=.1,position=pd)+geom_line(position=pd)+geom_point(position=pd)d <- ggplot(mtcars, aes(cyl, mpg)) + geom_point()
d + stat_summary(fun.data = "mean_se", colour = "red", size = 1)
A more general answer: in gglot2 2.0.0 the arguments to the function fun.data are no longer passed through ... but instead as a list through formal parameter fun.args. The code below is the exact equivalent to that in the original question.
ggplot(df, aes(x=condition, y=rt, fill=condition)) +
stat_summary(fun.y = mean, geom = "bar", colour="black",size=.3) +
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), geom = "errorbar")
or using code that can be run:
d <- ggplot(mtcars, aes(cyl, mpg)) + geom_point()
d + stat_summary(fun.data = "mean_cl_normal", fun.args = list(mult = 1), colour = "red", size = 1)