panel - Stripplot showing mean+sd [r] -
hi want plot stripplot showing mean+sd. cannot show boxplot because have less 5 values, want use mean , sd. problem cannot calculate mean , sd inside group, rather 2 means represented in both groups , and same segments.
require(lattice) stripplot(l ~ medium, parameters, ylab=list(expression("lag phase - h"),cex=1.5), xlab=list("medium", cex=1.5), auto.key=list(columns=2, rectangles=t, points=f, pch=16, at=null ), ylim=c(-2,15), up=parameters$l+parameters$sd.l, lo=parameters$l-parameters$sd.l, panel=function(x,y,up,lo,...){ xj=jitter(as.numeric(x), factor=0.5) panel.stripplot(xj,y,pch=16 , alpha=0.5 , factor=0.2, cex=1.2 , ...) panel.abline(h=0,col="black",...) panel.arrows(x0=xj, y0=lo, x1=xj, y1=up,code=3, angle=90, length=0.05 ,alpha=0.5) panel.dotplot(x=x, y=tapply(y,x,mean), col="red") panel.segments(x0=x,x1=x,y0=mean(y)-sd(y),y1=mean(y)+sd(y),col="red") } )
if condition on medium
, ~l|medium
rather l~medium
can calculate mean , sd each level within panel function.
for example
stripplot(~sepal.length|species,iris, panel=function(x,y,...) { m=mean(x) panel.stripplot(x,y,...) panel.stripplot(m,y,pch="|",cex=2,col=2) } )
otherwise can calculate mean , sd each level outside of stripplot
, using by
or aggregate
or similar , add these plot.
Comments
Post a Comment