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.
On Wednesday 08 September 2004 23:18, Leon Barmuta wrote:> 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 panelWhat exactly do you mean by that? Do you want the strips and and panel boundary for that panel not to be shown? There's no way of doing that as long as you have 2 different conditioning variables. The plot here is like a matrix, you cannot remove one element from it, you have to remove a whole column or a whole row. The best suggestion I can give you is to use the interaction facc:facb as your conditioning variable. bwplot would see this as a single factor (so the array structure is lost, and you just have a vector of plots), and it will simply drop the unused combination: plot1 <- bwplot( dv ~ faca | facc:facb, data=df2, layout = c(4, 2)) plot1 plot2 <- update(plot1, skip=c(rep(F, 3), T, rep(F, 4))) plot2 Deepayan> # 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. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
I have the same problem. As far as I can see, the only thing you can do is : attach(df2) group=paste(facb,facc,sep=" ") bwplot( dv ~ faca | factor(group)) Alex -----Original Message----- From: Leon Barmuta [mailto:Leon.Barmuta at utas.edu.au] Sent: September 9, 2004 1:19 AM To: r-help at stat.math.ethz.ch Subject: [R] Skipping panels in Lattice 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. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html