[R] How to control in order of groups in xyplot

Peter Ehlers ehlers at ucalgary.ca
Sun Oct 31 14:21:15 CET 2010


On 2010-10-31 01:19, Rainer Hurling wrote:
> A working minimal example would have been better, see FAQ.
>
> But I think you are looking for the following:
>
> X2<- factor(c("m=2", "m=5", "m=10"), levels=c("m=2", "m=5", "m=10"))
>
> Here levels are ordered in your way. There might be other solutions for
> this ordering problem.
>
That would be the best way for this (common) situation since
the ordering is not likely to be wanted in any other way.

For playing with different orderings, lattice provides
the index.cond argument described in the '...' part of
help(xyplot).

   -Peter Ehlers

> Hope it helps,
> Rainer
>
>
> On 31.10.2010 06:55 (UTC+1), Jie Liu wrote:
>> Hi guys,
>>
>> I used the following R code to generate one plot
>>
>> library(lattice)
>> xyplot(Y~X1|as.factor(X2)*as.factor(X3), groups = as.factor(X4),
>> data=mydata)
>>
>> Both X2 and X3 have three values. X4 has two values. I got 3x3 grids and in
>> each grid there are two curves about y~x1 for the two X4 values. I am quite
>> happy with the plot except that I need a different layout of the 3x3 layout.
>> For example, X2={"m=2", "m=5", and "m=10"} and it plots with the order
>> "m=10", "m=2", and "m=5". Is there any way I can control the order of the
>> groups in the whole plot? Thanks a lot,
>>
>> --Jerry
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list