[R] using perm.cond & index.cond in lattice package

8rino-Luca Pantani ottorino-luca.pantani at unifi.it
Mon Jul 5 16:57:35 CEST 2004


Dear R users,
this is my first question to the list.
I hope it will be not a trivial one.

My problem is to change the order in which the panel are plotted in a
lattice/Trellis plot.
I've read the S-plus Trellis Graphics user manual, in which there is a
function called "reorder.factor",
that, as far as I can catch from ?xyplot, in the lattice package is
substituted by two others:
"index.cond" & "perm.cond"


here below the (fictitious) data

cbind.data.frame(TREAT=c(rep(c("YES", "NO"), each=12)),
                 OM=rep(rep(c(5, 1, 3, 7), each=3), 2),
                 LOCATION=rep(rep(c("here5%OM", "there1%OM",
"elsewhere3%OM",
                                               "overthere7%OM"),
                                      each=3), 2),
                 Y=c(rnorm(3, mean=5),rnorm(3, mean=1),rnorm(3,
mean=3),rnorm(3, mean=7),
                     rnorm(3, mean=6),rnorm(3, mean=2),rnorm(3,
mean=4),rnorm(3, mean=8))
                )->mydframe
library(lattice)
bwplot(Y~TREAT|LOCATION, data=mydframe)
#The panels are plotted in alphabetical order, but I would rather have
something like
bwplot(Y~TREAT|OM, data=mydframe)
# i.e. the panels ordered by OM (Organic Matter) content
#but with LOCATION written in the strip.
#From
#str(bwplot(Y~TREAT|OM, data=mydframe))
#I can see that
# $ index.cond       :List of 1
# ..$ : int [1:4] 1 2 3 4
# $ perm.cond        : num 1
#so I tried
bwplot(Y~TREAT|LOCATION,
       data=mydframe,
       index.cond=
list((1:4)[order(unique(mydframe$OM[order(mydframe$LOCATION)]))])
       )
#and it seems to work, but without the darker tag for OM in the strips.

Now I have one perplexity and one question:

The last "list((1:4)[order(...." works fine, but it seems to me inelegant,
too complicate
                                        and not practical for plots with
more factors.
Any suggestion to simplify/improve the matter?

How can I keep the tags in the strips, still ordering the panels by OM?

Thanks in advance.

PS
The following lines are copied from ?xyplot
(I suspect that "order.cond" stands for "index.cond",
since I cannot find it in any other page of the lattice help, nor in the
general help)

 The order in which the panels are drawn depends on the order
          in which the conditioning variables are specified ('g1'
          varies fastest). Within a conditioning variable, the order
          depends on the order of the levels (which for factors is
          usually in alphabetical order). Both of these orders can be
          modified using the 'order.cond' and 'perm.cond' arguments,
          typically in the 'update' method.

Ottorino-Luca Pantani, Università di Firenze
Dip. Scienza del Suolo e Nutrizione della Pianta




More information about the R-help mailing list