introduction
latticeExtra is an R package (i.e. a package for the R statistical computing environment), providing functions for generating statistical graphics. It extends the Lattice framework (lattice package), which is an implementation of Trellis graphics in R.
Many of the functions and datasets in latticeExtra are described in Deepayan Sarkar's book, Lattice: Multivariate Data Visualization with R. That site also includes figures and code.
The package is maintained by Deepayan Sarkar and Felix Andrews.
This page gives only a single example of each major function. Follow the links to further details and examples.
For more information, see
general statistical plots
rootogram
One example:
rootogram(~x, dfun = function(x) dpois(x, lambda = 50))
segplot
One example:
segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male,
data = subset(USCancerRates, state == "Washington"), draw.bands = FALSE,
cente....
ecdfplot
One example:
ecdfplot(~height | voice.part, data = singer)
marginal.plot
One example:
marginal.plot(enviro[, 1:5], data = enviro, groups = is.windy,
auto.key = list(lines = TRUE))
functions of one variable
panel.smoother
One example:
xyplot(y + y2 ~ x, xy) + glayer(panel.smoother(...))
panel.quantile
One example:
update(xyplot(y ~ x, xy) + layer(panel.quantile(x, y, tau = c(0.5,
0.9, 0.1), superpose = TRUE)), auto.key = list(text = paste(c(50,
90, 10), "% qua....
panel.xblocks
One example:
xyplot(flow) + layer_(panel.xblocks(time(flow), months(flowdates),
col = c("lightgrey", "#e6e6e6"), border = "darkgrey"))
panel.xyarea
One example:
xyplot(sunspot.year, panel = panel.xyarea, origin = 0, aspect = "xy",
cut = list(n = 3, overlap = 0))
panel.tskernel
One example:
xyplot(sunspot.year) + layer(panel.tskernel(x, y, width = 20,
c = 3, col = 1, lwd = 2))
horizonplot
One example:
horizonplot(sunspots, cut = list(n = 23, overlap = 0), scales = list(y = list(relation = "same"),
draw = FALSE), origin = 100, strip.left = FALSE) + lay....
functions of two variables
mapplot
One example:
mapplot(county ~ log10(population), ancestry, map = county.map,
colramp = NULL)
tileplot
One example:
tileplot(z ~ x * y, xyz, border = "black", col.regions = grey.colors(100),
pch = ifelse(is.na(xyz$z), 4, 21), panel = function(...) {
panel.fill(....
panel.levelplot.points
One example:
levelplot(depth ~ long + lat | Magnitude, data = quakes.ordered,
panel = panel.levelplot.points, type = c("p", "g"), aspect = "iso",
prepanel = prep....
panel.2dsmoother
One example:
levelplot(z ~ x * y, xyz, panel = panel.levelplot.points, cex = 1.2) +
layer_(panel.2dsmoother(..., n = 200))
dendrogramGrob
One example:
levelplot(x[row.ord, col.ord], aspect = "fill", scales = list(x = list(rot = 90)),
colorkey = list(space = "left"), legend = list(right = list(fun = den....
utilities
useOuterStrips
One example:
xyplot(mpg ~ disp | HP + factor(cyl), mtcars, layout = dimx,
par.strip.text = list(lines = 0.5), strip = new.strip, strip.left = new.strip.left,
par....
resizePanels
One example:
dotplot(state.name ~ Frost | reorder(state.region, Frost), data = state,
layout = c(1, 4), scales = list(y = list(relation = "free")),
par.settings ....
panel.ablineq
One example:
xyplot(ysim ~ xsim) + layer(panel.ablineq(lm(y ~ x), r.sq = TRUE,
rot = TRUE, at = 0.8, pos = 3), style = 1) + layer(panel.ablineq(lm(y ~
x + 0), r.....
panel.scaleArrow
One example:
xyplot(EuStockMarkets) + layer(panel.scaleArrow(x = 0.99, append = " units",
col = "grey", srt = 90, cex = 0.8))
panel.3dmisc
One example:
cloud(as.table(prop.table(Titanic, margin = 1:3)[, , , 2]), type = c("p",
"h"), zlab = "ProportionnSurvived", panel.3d.cloud = panel.3dbars,
xbase ....
extended trellis framework
layer
One example:
qua + layer_(panel.contourplot(x = gridlon, y = gridlat, z = dist,
contour = TRUE, subscripts = TRUE), data = newdat)
as.layer
One example:
xyplot(fdeaths ~ mdeaths) + as.layer(bwplot(~mdeaths, box.ratio = 0.2),
y.same = FALSE)
doubleYScale
One example:
doubleYScale(obj1, obj2, add.ylab2 = TRUE)
c.trellis
One example:
update(c(xyplot(lat ~ long | equal.count(depth, 3), quakes, aspect = "iso",
pch = ".", cex = 2, xlab = NULL, ylab = NULL), histogram(quakes$depth),
....
styles
style example
One example:
xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
iris, type = c("p", "r"), jitter.x = TRUE, jitter.y = TRUE,
factor = 5, auto.key = l....
custom.theme
One example:
xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
iris, type = c("p", "r"), jitter.x = TRUE, jitter.y = TRUE,
factor = 5, auto.key = l....
theEconomist.theme
One example:
trellis.last.object() + layer_(panel.xblocks(x, x >= 1980, col = "#6CCFF6",
alpha = 0.5)) + layer(panel.text(1988, 180, "Forecast", font = 3,
pos = ....
data
postdoc
One example:
barchart(prop.table(postdoc, margin = 1), auto.key = TRUE, xlab = "Proportion")
biocAccess
One example:
xyplot(stl(ts(biocAccess$counts[1:(24 * 30)], frequency = 24),
"periodic"), strip.left = strip.custom(horizontal = FALSE,
strip.names = FALSE, strip....
EastAuClimate
One example:
segplot(siteNames ~ WinterMinTemp + SummerMaxTemp, EastAuClimate,
level = RainDays, sub = "Color scale: number of rainy days per year",
xlab = "Temp....