[R] xyplot question

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Dec 6 21:12:22 CET 2005


On 12/6/05, Christoph Scherber <Christoph.Scherber at uni-jena.de> wrote:
> Dear R users,
>
> I have a question regarding the use of xyplot in the lattice() package.
> I have two factors (each with two levels), and IÂ´d like to change the
> order of the panels in a 2x2 panel layout from the default alphabetic
> order that R uses based on the names of the factor levels.
>
> My approach is (in principle)
>
> xyplot(y~x|Factor1+Factor2)
>
> LetÂ´s assume, my factor levels for Factor1 are A and B,
> and for Factor2 theyÂ´re C and D, respectively.
>
> Now the default arrangement of my panels would be (from bottom top left

I assume you mean 'top left'

> to bottom right): "BC","CA","BD","AD"

No it won't, unless you meant

xyplot(y~x|Factor2+Factor1)

Instead of describing your problem 'in principle' (which can be very
confusing when you make a mistake), please do as the posting guide
asks and give a reproducible example. Anyone trying to answer you will
have to come up with an example anyway, and since it's your problem,
it might as well be you.

> What IÂ´d like to have is "BD","AC","BC","AD".

This is impossible if you have two conditioning factors (whichever way
you count, the combination following "BD" has to have at least one of
"B" and "D" in it). If you want to lose the 2-factor structure, create
an interaction, after which you can reorder its levels any way you
want, e.g.

d <-
    data.frame(f1 = sample(gl(2, 10, labels = LETTERS[1:2])),
               f2 = sample(gl(2, 10, labels = LETTERS[3:4])),
               x = rnorm(20),
               y = rnorm(20))

xyplot(y ~ x | f1:f2, d)[c(1, 2, 4, 3)]

which is a shortcut for

xyplot(y ~ x | f1:f2, d, index.cond = list(c(1, 2, 4, 3)))

-Deepayan

> Can anyone tell me how to solve this problem easily?
>
> IÂ´ve read that using "perm.cond" and/or "index.cond" could solve this
> problem, but couldnÂ´t find an appropriate example, unfortunately...




More information about the R-help mailing list