[R] How to add a line of "mean" to the bwplot (lattice package)

Bert Gunter gunter.berton at gene.com
Sun Jan 25 19:17:37 CET 2015


Call a custom panel function that adds horizontal lines at the means
of your groups. Something like (for vertical boxes, i.e.horiz=FALSE;
make appropriate change for horizontal boxes)


panel.mn <- function(x,y,box.width=.5,horiz=FALSE,...){
  y <- tapply(y,x,mean,na.rm=TRUE)
  x <- seq_along(y)
                 y0 = y,y1=y,...)

bwplot(your.y ~ your.x, panel=panel.mn,...)

## where ... means more arguments specifying colors, bwplot
parameters, etc. if desired


Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll

On Sun, Jan 25, 2015 at 7:06 AM, Jun Shen <jun.shen.ut at gmail.com> wrote:
> Dear list,
> The bwplot generates box plots with a dot in median. How do I add a line of
> "mean" to the boxes? Thanks a lot.
> Jun
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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