[R] Lattice side by side boxplots with average

maxbre mbressan at arpa.veneto.it
Tue May 8 17:32:59 CEST 2012


Given the following example

library(lattice) 
attach(barley)

After a long meandering around the web I managed to get a side by side
boxplots through:

bwplot(yield ~ site, data = barley, groups=year,
       pch = "|", box.width = 1/3,
       auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),
       panel = panel.superpose,
       panel.groups = function(x, y, ..., group.number) {
         panel.bwplot(x + (group.number-1.5)/3, y, ...)
       }
       )

now, my objective is to superpose the average for each boxplot;

I’ve been learning, again somewhere around the web, that this task has
something to do (obviously) first of all with the calculation of the
averages, i.e. something like:

mean.values <- tapply(y, x, mean)

and then with the superposition of relative average values to the boxplots,
i.e. something like:

panel.points(…, mean.values, ..., pch = 17)

but for some reasons I’m not able to properly combine these code snippets in
a successful way

any help much appreciated, thank you



--
View this message in context: http://r.789695.n4.nabble.com/Lattice-side-by-side-boxplots-with-average-tp4617831.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list