[R] R help: reorder columns in an xyplot

David Winsemius dwinsemius at comcast.net
Mon Nov 8 06:02:28 CET 2010


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

> 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=
> but get:
> Error in length(X) : 'X' is missing

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.

-- 
David.
>
> 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.
>
>
> -- 
> Michael S. Rentz
> PhD Candidate, Conservation Biology

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list