[R] Skipping panels in Lattice

Leon Barmuta Leon.Barmuta at utas.edu.au
Thu Sep 9 06:18:49 CEST 2004


Dear all,

I wish to generate a lattice boxplot which skips an empty cell in a design. 
I have trawled r-help, scruitinized xyplot(lattice) help page, and merrily 
reproduced examples of using skip from a couple of previous r-help queries 
and the example given in Pinheiro & Bates. But I must be missing something...

Here's an example (running R 1.9.1 on Win2k):

# generate some data

df1 <- data.frame(expand.grid(obsnum=seq(1, 15, 1), faca=c("A1", "A2", "A3"),
     facb=c("B1","B2", "B3", "B4"), facc=c("C1","C2")), dv=rpois(15*3*4*2,10))

# now get rid of the cell B4 & C1 to simulate a missing treatment combination

df2 <- df1[df1$facb !="B4" | df1$facc !="C1", ]

# plain vanilla lattice plot generates an empty panel corresponding to the 
empty cell

plot1 <- bwplot( dv ~ faca | facb*facc, data=df2)
plot1

# now try to skip the empty panel
# turn plot history on so that the separate pages can be recalled

plot2 <- update(plot1, skip=c(rep(F, 3), T, rep(F, 4)))
plot2

and the 4th panel position of the bottom row is skipped, BUT the B4&C1 cell 
is shunted to the top left of row 1 and the last panel of plot1 is now 
moved to page 2. Messing with layout= doesn't help, neither does 
substituting NA for the values of the missing cell (instead of cutting it 
out of the data frame). I also get the same behaviour for stripplot and 
dotplot too.

Apologies if I've missed a previous solution to this during my searches of 
the archive.

Regards,

Leon Barmuta
School of Zoology & TAFI, University of Tasmania, Australia.




More information about the R-help mailing list