Cable, Samuel B Civ USAF AFMC AFRL/RVBXI
2009-Mar-25 15:15 UTC
[R] need help with ordering of plots
I want to do a series of contour plots, 4 in all. The data is coming from a data frame named "nd.frame", which has elements "xdf", "ydf", "zdf", and "pndt". I am treating "pndt" as a factor, and it has four levels. I make a call to the lattice graphics routine "contourplot" like so: contourplot(zdf~xdf*ydf|factor(pndf),data=nd.frame)>From this I get a 2x2 grid of four contour plots. So far so good.The problem - a big problem in my situation - is that the arrangement is in the order 3 | 4 ------ 1 | 2 What I need is 1 | 2 ------ 3 | 4 Or 1 | 3 ------ 2 | 4 How do I convince R to reorder my plots? The common wisdom seems to be that I should reorder the data in the data frame via the reorder() function. My efforts at this have been fruitless, as I can't seem to understand what the output of reorder() actually is or how to use it. And none of the documentation I have read on reorder()makes any sense to me at all. Can anyone help? Also, not to get snippy, but it seems to me that a very obvious and useful flag for the contourplot() function would be some sort of order flag, which could take arguments like "reverse" or "byrow" or "bycolumn". As far as I can tell, nothing of the sort exists. Am I right about this? If so, why is this the case? A flag in a function would be a much more convenient way of changing plotting order than actually messing around with your data. Thanks. [[alternative HTML version deleted]]
On 3/25/2009 11:15 AM, Cable, Samuel B Civ USAF AFMC AFRL/RVBXI wrote:> I want to do a series of contour plots, 4 in all. The data is coming > from a data frame named "nd.frame", which has elements "xdf", "ydf", > "zdf", and "pndt". I am treating "pndt" as a factor, and it has four > levels. I make a call to the lattice graphics routine "contourplot" > like so: > > > > contourplot(zdf~xdf*ydf|factor(pndf),data=nd.frame) > > > >>From this I get a 2x2 grid of four contour plots. So far so good. > > > > The problem - a big problem in my situation - is that the arrangement is > in the order > > > > 3 | 4 > > ------ > > 1 | 2 > > > > What I need is > > > > 1 | 2 > > ------ > > 3 | 4 > > > > Or > > > > 1 | 3 > > ------ > > 2 | 4 > > > > How do I convince R to reorder my plots? > > > > The common wisdom seems to be that I should reorder the data in the data > frame via the reorder() function. My efforts at this have been > fruitless, as I can't seem to understand what the output of reorder() > actually is or how to use it. And none of the documentation I have read > on reorder()makes any sense to me at all. Can anyone help? > > > > Also, not to get snippy, but it seems to me that a very obvious and > useful flag for the contourplot() function would be some sort of order > flag, which could take arguments like "reverse" or "byrow" or > "bycolumn". As far as I can tell, nothing of the sort exists. Am I > right about this? If so, why is this the case? A flag in a function > would be a much more convenient way of changing plotting order than > actually messing around with your data.Trellis graphics normally plot things in the order you're seeing, but a number of people (including you, it seems!) don't like that ordering. Lattice includes the "as.table=TRUE" argument to high level functions (including contourplot) to put things in a more table-like ordering. Duncan Murdoch
Cable, Samuely <at> hanscom.af.mil>> I want to do a series of contour plots, 4 in all. The data is coming > from a data frame named "nd.frame", which has elements "xdf", "ydf", > "zdf", and "pndt". I am treating "pndt" as a factor, and it has four > levels. I make a call to the lattice graphics routine "contourplot" > like so: > > The problem - a big problem in my situation - is that the arrangement is > in the orderI know, it's really a bit of guesswork which parameters work for special plots. Nevertheless, if you are unsure, always look on the xyplot page and try one of the parameter there. Your friend is called as.table. If you need a really crazy ordering, reorder your factor: Dieter #---------------------------------------------------- library(lattice) x <- seq(pi/4, 5 * pi, length.out = 10) y <- seq(pi/4, 5 * pi, length.out = 10) r <- as.vector(sqrt(outer(x^2, y^2, "+"))) grid <- expand.grid(x=x, y=y) grid$z <- cos(r^2) * exp(-r/(pi^3)) grid$class= rep(letters[1:4],each=25) contourplot(z~x*y|class, grid, region = TRUE,as.table=TRUE) grid$rclass = factor(grid$class,levels=c("c","b","a","d")) contourplot(z~x*y|rclass, grid, region = TRUE,as.table=TRUE)