[R] how to specify ggplot2 facet plot order

Chris Friedl cfriedalek at gmail.com
Wed Feb 27 11:23:22 CET 2008

Hi Thierry

thanks for your help. I've been searching the R-help archives for posts by
you and Hadley as a way to learn ggplot details so I appreciate your help to
the R community.

I wasn't aware of the levels option in the factors function. In my real
application I get the data using read.csv and factor assignment happens
automagically. Is there a way to control the level assignments at the input
stage? Can't see anything to that effect in help.

Sorry for the cut & paste error ... getting used to Xemacs on Windows. I
used emacs years ago on Unix but  now my environment is Windows. So far I
find the Xemacs/Ess combo to be very powerful and flexible. Just need to get
used to C-x C-c etc differences.

ONKELINX, Thierry wrote:
> Chris,
> The order of the facets row or column depend on the order in the
> associated factor. The code below is what you want. Note that I have
> changed 'cases' in 'series' because your example was not reproducible as
> a definition of 'cases' was missing.
> library(ggplot2)
> series <- c('C2','C4','C8','C10','C15','C20')
> series <- factor(series, levels = series)
> ids <- c('ID1','ID2','ID3')
> mydata <-
> data.frame(SERIES=rep(series,30),ID=rep(ids,60),VALUE=rnorm(180))
> qplot(VALUE, data = mydata, geom="density", facets=SERIES ~ ID) 
> Thierry

View this message in context: http://www.nabble.com/how-to-specify-ggplot2-facet-plot-order-tp15705404p15710275.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list