[R] need help with ordering of plots

Duncan Murdoch murdoch at stats.uwo.ca
Wed Mar 25 18:04:17 CET 2009


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




More information about the R-help mailing list