From: ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be>

Date: Wed, 27 Feb 2008 10:38:40 +0100

ir. Thierry Onkelinx

Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest

Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance

Gaverstraat 4

9500 Geraardsbergen

Belgium

tel. + 32 54/436 185

Thierry.Onkelinx_at_inbo.be

www.inbo.be

Date: Wed, 27 Feb 2008 10:38:40 +0100

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

ir. Thierry Onkelinx

Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest

Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance

Gaverstraat 4

9500 Geraardsbergen

Belgium

tel. + 32 54/436 185

Thierry.Onkelinx_at_inbo.be

www.inbo.be

Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----

Van: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
Namens Chris Friedl

Verzonden: woensdag 27 februari 2008 4:39
Aan: r-help_at_r-project.org

Onderwerp: [R] how to specify ggplot2 facet plot order

Hi, new to R and ggplot2. I've been trying to get a facet plot in which
the

order of the facets is as I require, rather than ordered numerically,
alphabetically, by Roman numerals, mean (answers to these were posted
here

after much searching). Here's some test code to demonstrate what I get.

series = c('C2','C4','C8','C10','C15','C20')
ids = c('ID1','ID2','ID3')

mydata <-

data.frame(SERIES=rep(cases,30),ID=rep(ids,60),VALUE=rnorm(180))
qplot(VALUE, data = mydata, geom="density", facets=SERIES ~ ID)

the facet rows are plotted in alpha order, namely, C10, C15, C2, C20,
C4,

C8. I want them plotted in the order specified by series.

I've looked at reorder to reorder the factor called SERIES but that
requires

a vector of the same length upon which the ordering is defined through
some

function. I guess my noobness with all things R has brought me to a
grinding

halt.

I can conceive an algorithm but don't know how to implement.
1. create myordervector of length(SERIES) comprising integers in a
mapping

C2: 1, C4: 2, C8: 3 ...

2. reorder using this vector as follows:
mydata <- with(mydata, reorder(SERIES, myordervector , as.numeric))
3. Then plot as above

Is this remotely sensible? Perhaps the order is determined at plot time
rather than from the data.frame. In this case I guess the reordering
before

plotting is moot. I'm stuck. Can anyone help out please.

thanks.

-- View this message in context: http://www.nabble.com/how-to-specify-ggplot2-facet-plot-order-tp15705404 p15705404.html Sent from the R help mailing list archive at Nabble.com.Received on Wed 27 Feb 2008 - 09:44:19 GMT

______________________________________________

R-help_at_r-project.org mailing list 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.

______________________________________________

R-help_at_r-project.org mailing list 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.

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Wed 27 Feb 2008 - 10:30:17 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*