[R] basic bwplot query

Deepayan Sarkar deepayan at stat.wisc.edu
Sun Nov 7 00:27:28 CET 2004

On Saturday 06 November 2004 16:54, Kieran Healy wrote:
> Hi -
> I have some data consisting of a number of observations within each
> of 15 countries. Each country falls into one of two groups. I'd like
> to use the lattice library's bwplot to present boxplots of the
> country-level data, with a separate panel for each group, but showing
> only the relevant countries in each panel.  Here's an analogous
> example using the "singer" data provided with the lattice. Say we
> assign the voice parts to groups, "M" and "F":
> tmp <- rep("F",128)
> tmp2 <- rep("M",length(129:nrow(singer)))
> sex <- c(tmp,tmp2)
> We'd like a two-panel figure showing the voice part boxplots for
> groups "M" and "F", but each panel should list only  those voice
> parts falling in its group. This way doesn't quite work:
> bwplot(voice.part ~ height | sex, data=singer, xlab="Height
> (inches)",layout=c(1,2))
> How can I have rows belonging to the "F" group just not appear at all
> in the "M" panel and vice versa? I guess this is quite
> straightforward, but I'm going about it in the wrong --- do I need to
> provide some extra information about subscripts via a panel function?
> I'd be grateful for any advice.


bwplot(voice.part ~ height | sex, data=singer,
       xlab="Height (inches)",layout=c(1,2),
       scales = list(y = list(relation = "free")))

Note that this will only work in R 2.0.0 or better.


More information about the R-help mailing list