[R] bwplot() {lattice}
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Feb 26 09:51:19 CET 2010
On Fri, Feb 26, 2010 at 8:30 AM, Peng Cai <pengcaimaillist at gmail.com> wrote:
> Hi All,
>
> I'm trying to plot boxplot graph. I tried barchart with "groups=" option and
> it worked fine. But when I try to generate same kind of graph using
> bwplot(), "groups=" option doesn't seem to work. Though this works,
>
> yield ~ variety | site * year
>
> I'm thinking why "groups=" doesn't work in this case, can anyone help
> please...
Let's see...you have exactly one observation per site/variety/year
combination (otherwise the barchart wouldn't have made sense). So in
the boxplot you want (which is supposed to summarize a distribution,
not a single point), you only have that single point to plot. For
that, you can use
dotplot(yield ~ variety | site, data = barley, auto.key = TRUE,
groups = year, layout = c(6,1), scales=(x=list(rot=45)))
If you try to come up with a more sensible example, you would realize
that boxplots are already grouped (the grouping variable is the
categorical variable in the formula y ~ x, not the 'groups' argument).
Compare
## Is this really what you want?
bwplot(yield ~ variety, data = barley, col = 1, pch = 16,
panel = panel.superpose, panel.groups = panel.bwplot,
groups = year, scales=(x=list(rot=45)))
bwplot(yield ~ year | variety, data = barley,
scales=(x=list(rot=45)), layout = c(10, 1))
-Deepayan
>
> #Code:
> library(lattice)
> barchart(yield ~ variety | site, data = barley,
> groups = year, layout = c(1,6),
> auto.key = list(points = FALSE, rectangles = TRUE, space = "right"))
>
> bwplot(yield ~ variety | site, data = barley,
> groups = year, layout = c(6,1), scales=(x=list(rot=45)),
> auto.key = list(points = FALSE, rectangles = TRUE, space = "right"))
More information about the R-help
mailing list