[R] Lattice: barchart, error bars and grouped data

Johannes Graumann johannes_graumann at web.de
Mon Mar 8 10:04:15 CET 2010


Hi,

How can I, given the code snippet below, draw the error bars in the center 
of each grouped bar rather than in the center of the group?

Thanks for any hints,

Joh

library(lattice)

barley[["SD"]] <- 5
barchart(
  yield ~ variety | site, 
  data = barley,
  groups=year,
  origin=0,
  lowDev=barley[["SD"]],
  highDev=barley[["SD"]],
  panel = function(
    x,
    y,
    ...,
    lowDev,
    highDev
  ){
    panel.barchart(x, y, ...)
    panel.segments(
       as.numeric(x),
       as.numeric(y) - lowDev,
       as.numeric(x),
       as.numeric(y) + highDev,
       col = 'red', lwd = 2,
       ...)
  }
)



More information about the R-help mailing list