[R] Lattice: How to do error bars

Deepayan Sarkar deepayan.sarkar at gmail.com
Sat Aug 22 10:21:48 CEST 2009


On 8/11/09, Alex van der Spek <amvds at xs4all.nl> wrote:
> I am trying to add 2 stdev error bars to lattice type plots:
>
>  panel.ebar<-function(x,y,dy=NULL,...) {
>         panel.xyplot(x,y,...)
>         panel.segments(x,y-dy,x,y+dy,...)
>  }
>
>  Then:
>
>  xyplot(y~x|fc,data=dat,dy=dat$dy,panel=panel.ebar)
>
>  This adds error bars but they are not conditioned on the factor fc.
>
>  xyplot(y+I(y-dy)+I(y+dy)~x|fc,data=dat)
>
>  This produces 3 series of points in different colors, conditioned on fc
>  as the data is now grouped per panel.
>
>  Obviously I need a combination of the above two. I can't figure it out.
>
>  Any help? Just point to docs if avaiable. The R doc is excellent. Most
>  of the time I can save myself.

See demo("intervals", package="lattice") for the basic approach.

There are a couple of different functions that will take care of the
details for you: xYplot() in the Hmisc package and segplot() in the
latticeExtra package.

-Deepayan




More information about the R-help mailing list