[R] problem with ggplot2 boxplot, groups and facets

Zeljko Vrba zvrba at ifi.uio.no
Tue May 5 22:59:02 CEST 2009


I have a following problem:

The call

qplot(wg, v.realtime, data=df.best.medians$gv1, colour=sp,  geom="boxplot")

works nice: for each value of the wg factor I get two box-plots (two levels in
the sp factor) in different colours, side-by-side, centered at the wg x-axis.
However, I want to separate the data belonging to different levels of the n
factor, so I add the facets option:

qplot(wg, v.realtime, data=df.best.medians$gv1, facets = . ~ n,
  colour=sp, geom="boxplot")

At this point, the things break with more than 50 warnings, here are the
first few:

1: In Ops.factor(width, n) : / not meaningful for factors
2: In Ops.factor(n, 1) : - not meaningful for factors
3: In Ops.factor(2, n) : * not meaningful for factors
4: In Ops.factor(d_width, n) : / not meaningful for factors

Interestingly enough, removing the colour option, also produces a boxplot,
but now the data for the two levels of sp are drawn in the same box, i.e.,
the following works:

qplot(wg, v.realtime, data=df.best.medians$gv1, facets = . ~ n, geom="boxplot")

but does not plot what I want.

Any suggestions for a workaround?

Thanks.




More information about the R-help mailing list