[R] Graphics Question

RICHARD M. HEIBERGER rmh at temple.edu
Fri Feb 19 01:35:44 CET 2010


## 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))



More information about the R-help mailing list