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. Thanks in advance! Alex van der Spek
Thank you Gerrit, Your suggestion proved right after all: This does put error bars (dy) on the points. You only need to figure out the proper y axis scaling.> xyplot(y~x|f,data=xy,groups=dy,panel=function(x,y,groups,subscripts,...){panel.xyplot(x,y,...) ;panel.segments(x,y+groups[subscripts],x,y-groups[subscripts],...)}) Regards, Alex van der Spek> Hello, Alex, > > not sure in this case, but I think you have to provide and use an argument > named "subscripts" for the panel function. See ?xyplot. > > > On Tue, 11 Aug 2009, Alex van der Spek 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. >> >> Thanks in advance! >> Alex van der Spek >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > Regards -- Gerrit > > --------------------------------------------------------------------- > AOR Dr. Gerrit Eichner Mathematical Institute, Room 305 E > gerrit.eichner at math.uni-giessen.de Justus-Liebig-University Giessen > Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany > Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/~gcb7 > --------------------------------------------------------------------- >
On Wed, Aug 12, 2009 at 7:19 AM, <amvds at xs4all.nl> wrote:> Thank you Gerrit, > > Your suggestion proved right after all: > > This does put error bars (dy) on the points. You only need to figure out > the proper y axis scaling. > >> xyplot(y~x|f,data=xy,groups=dy,panel=function(x,y,groups,subscripts,...) > {panel.xyplot(x,y,...) > ;panel.segments(x,y+groups[subscripts],x,y-groups[subscripts],...)})You might also want to check out the segplot function in latticeExtra (it has a few rough edges, but should mostly work). -Deepayan
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