Skip to content
Prev 131207 / 398502 Next

Multiple stacked barplots on the same graph?

St?phane CRUVEILLER <scruveil <at> genoscope.cns.fr> writes:
Check the following example on xyplot/lattice:

barchart(yield ~ variety | site, data = barley,
         groups = year, layout = c(1,6), stack = TRUE, 
         auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),
         ylab = "Barley Yield (bushels/acre)",
         scales = list(x = list(rot = 45)))

You have to reformat your data to the long format first for this, e.g. by using
reshape.

Comp  Cond  x
1     1     11.81
1     2      2.05

With allow.multiple=TRUE, it might be possible to avoid the reformatting, but I
never have used that form, because I the "long" had many advantages.

Dieter