Smit, A, Albertus, Dr
2002-Sep-25 09:31 UTC
[R] Re-ordering the order of lattice graphics panels
Dear all I have made some lattice graphs (bwplot(dead ~ treat | group,...). 'group' is a factor with three levels (Artemia larvae, Abalone larvae and Abalone spat), and the result is a graph with three panels corresponding to the levels in 'group', ordered in alphabetical order from bottom to top, as expected. How does one re-order the order in which the levels of 'group' in the graph? I want Abalone spat at the bottom, followed by Abalone larvae, and Artemia larvae at the top. I have read most of the help on bwplots, panel.functions etc., but I am sure there is something obvious and simple I have missed. Any help appreciated. Albertus Dr. Albertus J. Smit Department of Botany University of Cape Town Private Bag Rondebosch 7700 South Africa Tel. +27 21 689 3032 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Albertus, At 11:31 AM 9/25/2002 +0200, Smit, A, Albertus, Dr wrote:>I have made some lattice graphs (bwplot(dead ~ treat | group,...). >'group' is a factor with three levels (Artemia larvae, Abalone larvae >and Abalone spat), and the result is a graph with three panels >corresponding to the levels in 'group', ordered in alphabetical order >from bottom to top, as expected. > >How does one re-order the order in which the levels of 'group' in the >graph? I want Abalone spat at the bottom, followed by Abalone larvae, >and Artemia larvae at the top. I have read most of the help on >bwplots, panel.functions etc., but I am sure there is something >obvious and simple I have missed.You can specify the order of the levels of a factor using the levels argument to factor(); the default, as you mention, is to order the levels alphabetically. To change the order, group.2 <- factor(group, c("Abalone spat", "Abalone larvae", "Abalone spat")). This should give you what you want. John ----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Factor levels may be specified by argument levels in function factor. The following is an illustration:> dat <- data.frame(x=rnorm(12), y=rnorm(12), group=rep(c("Artemialarvae", "Abalone larvae", "Abalone spat"), 4))> dat$group <- factor(dat$group, levels=c("Abalone spat","Abalonelarvae", "Artemia larvae"))> bwplot(y ~ x | group, data=dat, layout=c(1,3))Jun On Wed, 25 Sep 2002, Smit, A, Albertus, Dr wrote:> Dear all > > I have made some lattice graphs (bwplot(dead ~ treat | group,...). > 'group' is a factor with three levels (Artemia larvae, Abalone larvae > and Abalone spat), and the result is a graph with three panels > corresponding to the levels in 'group', ordered in alphabetical order > from bottom to top, as expected. > > How does one re-order the order in which the levels of 'group' in the > graph? I want Abalone spat at the bottom, followed by Abalone larvae, > and Artemia larvae at the top. I have read most of the help on > bwplots, panel.functions etc., but I am sure there is something > obvious and simple I have missed. > > Any help appreciated. > > Albertus > > > > > Dr. Albertus J. Smit > Department of Botany > University of Cape Town > Private Bag Rondebosch > 7700 > South Africa > Tel. +27 21 689 3032 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._