Skip to content
Prev 293955 / 398502 Next

Lattice side by side boxplots with average

On Tue, May 8, 2012 at 9:32 AM, maxbre <mbressan at arpa.veneto.it> wrote:

            
Almost. You need to give panel.points the new x, and make sure the
right mean.values go to the right place because the order of tapply
output is not necessarily the same order as y, even though I never
quite understood why myself...
Bottom line, this should it:

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, ...)
         mean.values <- tapply(y, x, mean)
         panel.points(x + (group.number-1.5)/3, mean.values[x], pch=17)
})

Cheers