Skip to content
Prev 101709 / 398500 Next

adding error bars to lattice plots

Daniel E. Bunker said the following on 10/12/2006 11:48 AM:
Hi, Daniel,

Try this panel function:

panel.ci <- function(x, y, lx, ux, subscripts,
                      groups = NULL, pch = 16, ...) {
   x <- as.numeric(x)
   y <- as.numeric(y)
   lx <- as.numeric(lx[subscripts])
   ux <- as.numeric(ux[subscripts])
   par <- if(is.null(groups))"plot.symbol" else "superpose.symbol"
   sym <- trellis.par.get(par)
   col <- sym$col
   groups <- if(!is.null(groups)) {
     groups[subscripts]
   } else {
     rep(1, along = x)
   }
   ug <- unique(groups)
   for(i in seq(along = ug)) {
     subg <- groups == ug[i]
     y.g <- y[subg]
     x.g <- x[subg]
     lx.g <- lx[subg]
     ux.g <- ux[subg]
     panel.abline(h = unique(y.g), col = "grey")
     panel.arrows(lx.g, y.g, ux.g, y.g, col = 'black',
                  length = 0.25, unit = "native",
                  angle = 90, code = 3)
     panel.xyplot(x.g, y.g, pch = pch, col = col[i], ...)
   }
}