Hello All, I'm having some issues controlling graphics in R. I was wondering if anyone may help me tackle this problem: Given a data frame "X" with variables "Year", "Factor" (w/ n groups), and "Freq" How do I create a single graphic with the following plots aligned in a vertical stack? 1. box plot in the fashion Freq~Year|Factor 2. box plot ignoring Factor, Freq~Year Using the following code: library(lattice) tp1<-bwplot(Freq~Year,data=X,main="All data",ylab="Freq",xlab="Year",layout=c(1,1)) tp2<-bwplot(Freq~Year|Factor,data=X,ylab="Freq",xlab="Year",layout=c(1,2)) plot(tp1,split=c(1,1,1,2)); plot(tp2,split=c(1,2,1,2),newpage=FALSE) ...I've managed to get a graphic that looks like two unrelated images on one screen: one image with the plot without taking Factor into account; and the other image, a smooshed lattice plot consisting of n plots in one column with n rows. The axis are not aligned and scaled differently (in the second image the individual plots are half the height of in the first image). How can I fix this? It would be nice to create a graphic with all of the plots stacked on top of each other with the same axis dimensions and ranges. Thanks for your help in advance! -- Lanna Jin lannajin@gmail.com 510-898-8525 [[alternative HTML version deleted]]
## The grouped boxplot is one of the features included in the HH package. ## You will need to install HH if you do not yet have the HH package ## A similar example is posted on my website ## http://astro.ocis.temple.edu/~rmh/HH/bwplot-color.pdf ## This is fake data which I hope mimics the structure you hinted at. ## I am using n=10 levels of Factor and 6 Years ## with 5 observations at each Year:Factor value X <- data.frame(Year=rep(factor(1999:2004), each=10), Factor=factor(rep(1:10, 6)), Freq=1:60) X <- rbind(X,X,X,X,X) X$Freq <- X$Freq + rnorm(5*60, s=3) X$YearFactor <- with(X, interaction(Factor, Year)) ## install.packages("HH") ## if you do not yet have the HH package library(HH) b1 <- bwplot(Freq ~ Year, data=X, panel=panel.bwplot.intermediate.hh, col=1:6, scales=list(x=list(limits=c(0,7), at=1:6, labels=levels(X$Year))), main="Grouped") b2 <- bwplot(Freq ~ YearFactor, data=X, panel=panel.bwplot.intermediate.hh, col=rep(1:6, each=10), scales=list(x=list(limits=c(0,70)-5, at=seq(10,60,10)-5, labels=levels(X$Year))), main="Ungrouped") print(b1, split=c(1,1,1,2), more=TRUE) print(b2, split=c(1,2,1,2))