As part of their talk they had a little competition in visualising London Underground performance data, see their slides. Both made heavy use of the respective panelling / faceting capabilities. Additionally Rich used the
panel.groups
argument of xyplot
to fine control the content of each panel. Brilliant! I had never used this argument before. So, here is a silly example with the iris
data set to remind myself of panel.groups
in the future.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lattice) | |
my.settings <- list( | |
superpose.symbol=list(pch=19), | |
plot.line=list(col="black"), | |
plot.polygon=list(col=adjustcolor(col="steelblue", | |
alpha.f=0.5), | |
border="white") | |
) | |
xyplot(Sepal.Length ~ Sepal.Width, groups=Species, data=iris, | |
main="Lattice example with panel.groups", | |
par.settings = my.settings, | |
panel=panel.superpose, | |
panel.groups=function(x,y, group.number,...){ | |
specie <- levels(iris$Species)[group.number] | |
if(specie %in% "setosa"){ | |
panel.xyplot(x,y,...) | |
panel.abline(lm(y~x)) | |
} | |
if(specie %in% "versicolor"){ | |
panel.barchart(x, y) | |
} | |
if(specie %in% "virginica"){ | |
panel.rug(x, y) | |
} | |
} | |
) |