[R] Lattice side by side boxplots with average

ilai keren at math.montana.edu
Tue May 8 20:28:29 CEST 2012


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

> and then with the superposition of relative average values to the boxplots,
> i.e. something like:
>
> panel.points(…, mean.values, ..., pch = 17)

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
>
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list