[R] LATTICE. On skip, index.cond with a formula like Y~X|A+B

ottorino ottorino-luca.pantani at unifi.it
Tue Nov 16 13:01:29 CET 2010


Dear invaluable R-list,
my present problem is arranging/removing some panels in a lattice plot.

Please consider the following:

df.data <-
    cbind.data.frame(expand.grid(SUBJ=1:5,
                                 TREAT=LETTERS[1:4],
                                 REF=letters[1:4]
                                 )
                     )
df.data <-
    df.data[order(df.data$TREAT,df.data$REF), ]
df.data <-
    cbind.data.frame(df.data[,2:3],
                            X=1:5,
                            Y= c(
                            seq(1,100,length=5),
                            seq(1,10,length=5),
                            seq(1,50,length=5),
                            1:5,
                            ##
                            seq(1,10,length=5),
                            seq(1,100,length=5),
                            seq(1,50,length=5),
                            1:5,
                            ##
                            seq(1,10,length=5),
                            seq(1,50,length=5),
                            seq(1,100,length=5),
                            1:5,
                            ##
                            seq(1,10,length=5),
                            seq(1,50,length=5),
                            1:5,
                            seq(1,100,length=5)
                            )
                            )

# Plot the data:
# Note the interaction in the formula
# with this formula lattice draws a strip in the 
# form A:B in one line
(my.plot <-
    xyplot(Y ~ X|TREAT:REF,
       data = df.data,
       layout = c(4,4),
       aspect=1,
       panel = function(x, y, ...){
           panel.xyplot(x, y, lty=1, ...)
           panel.abline(coef(lm(y ~ x), col=2))
       })
 )

# Now imagine that I only need the elements off the diagonal,
# say the inferior ones.
# So I can write some lines using a convenient call to 
# "skip" and "index.cond"

update(my.plot,
       skip= c(0,0,0,1,0,0,1,1),
       index.cond=list(c(2,3,4,7,8,12)),
       layout=c(3,3))

# The lines above draw ALMOST what I'm looking for.
# My real problem is that I have factors with long 
# and unshrinkable names, that do not fit easily in one line.
#
# For sake of clarity and for other reasons I would like to plot
# something like the one below, with two strips and with the shingle
# BUT removing all the panels except the off diagonal inferior elements.

(my.plotTwoLines <-
 xyplot(Y ~ X|TREAT+REF,
       data = df.data,
       layout = c(4,4),
       aspect=1,
       strip= strip.custom(stile=3),
       panel = function(x, y, ...){
           panel.xyplot(x, y, lty=1, ...)
           panel.abline(coef(lm(y ~ x), col=2))
       })
 )

# The formula |TREAT+REF results in a 
# "index.cond" which is obviously a list with one element for
# each factor

my.plotTwoLines$index.cond

# In this case I think I can only remove columns or rows, but not single
# panels. 
# Any suggestion ?

# Thanks in advance for your time.

-- 
Ottorino-Luca Pantani, Università di Firenze
Dip.to di Scienze delle Produzioni Vegetali,
del Suolo e dell'Ambiente Forestale (DiPSA)
P.zle Cascine 28 50144 Firenze Italia
Ubuntu 10.04 -- GNOME 2.30.2
GNU Emacs 23.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version
2.18.0)
ESS version 5.11 -- R 2.12.0



More information about the R-help mailing list