Skip to content

R help: reorder columns in an xyplot

3 messages · rent0009 at umn.edu, David Winsemius, Michael Rentz

#
Hello. First post, though I have read scores. Mostly i can solve my 
problems reading the archives, but I lack the vocabulary to ask this one 
right. Any social faux pais, I apologize.

I am sure this is a very basic question and I am embarrassed to ask, but I 
spent several hours scouring the archives and trying various suggestions, 
but I am too new to get any of them to work.

I am trying to generate an xyplot (or bwplot) for a presentation on 
Tuesday. As part of my dissertation I have 3 treatments divided into 2 time 
periods (before and after treatment).

Code that works (stripped of labels) is:

xyplot(veg$litter_depth ~ veg$status | veg$treatment, layout=c(3,1), 
type=c("p","r"))

Status is "before" and "after" In essence I am plotting a change in litter 
depth (and about 50 other variables) over time for each of the treatments. 
This generates a graph with 3 separate plots, one for each treatment. The 
plot works, but after is on the left and before on the right. This bugs me.

I tried:
veg$status2 <- reorder(veg$status, new.order=c("before", "after"))
but get:
Error in length(X) : 'X' is missing

I also tried:
h <- xyplot(litter.cover ~ status | treatment, relevel(status, 
ref=c("before", "after")), data = veg)

but get:
Error in relevel(status, ref = c("before", "after")) : 
  object 'status' not found

I have noticed that folks request data, but I hope my question is basic 
enough without it.

Please be gentle and thank you in advance,

Mike.
#
On Nov 7, 2010, at 10:35 PM, rent0009 at umn.edu wrote:

            
To make this leass ambiguous you could have posted str(veg). Try  
(perhaps):

veg$status <- factor(vec$status, levels=c(c("before", "after"))

Then plot as before.
#
Mr. Dunlap and Dr. Winsemius:

Thank you both for your very quick, very handy, and very correct response. 
That was it. I only wish I had broken down and admitted defeat and asked 
for help hours ago.

That was indeed what I needed, now the before does indeed come before the 
after!

Thanks again,

Mike.
On Nov 7 2010, David Winsemius wrote: