default black and white custom theme custom theme 2 theEconomist classic gray

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

Trellis Displays of Tukey's Hanging Rootograms

Usage, Details, Examples

One example:

rootogram
 rootogram(~x, dfun = function(x) dpois(x, lambda = 50))   

segplot

Plot segments using the Trellis framework

Usage, Details, Examples

One example:

segplot
 segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male, 
    data = subset(USCancerRates, state == "Washington"), draw.bands = FALSE, 
    cente....   

ecdfplot

Trellis Displays of Empirical CDF

Usage, Details, Examples

One example:

ecdfplot
 ecdfplot(~height | voice.part, data = singer)   

marginal.plot

Display marginal distributions

Usage, Details, Examples

One example:

marginal.plot
 marginal.plot(enviro[, 1:5], data = enviro, groups = is.windy, 
    auto.key = list(lines = TRUE))   

functions of one variable

panel.smoother

Plot a smoothing line with standard error bounds.

Usage, Details, Examples

One example:

panel.smoother
 xyplot(y + y2 ~ x, xy) + glayer(panel.smoother(...))   

panel.quantile

Plot a quantile regression line with standard error bounds.

Usage, Details, Examples

One example:

panel.quantile
 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

Plot contiguous blocks along x axis.

Usage, Details, Examples

One example:

panel.xblocks
 xyplot(flow) + layer_(panel.xblocks(time(flow), months(flowdates), 
    col = c("lightgrey", "#e6e6e6"), border = "darkgrey"))   

panel.xyarea

Plot series as filled polygons.

Usage, Details, Examples

One example:

panel.xyarea
 xyplot(sunspot.year, panel = panel.xyarea, origin = 0, aspect = "xy", 
    cut = list(n = 3, overlap = 0))   

panel.tskernel

Plot a smoothed time series.

Usage, Details, Examples

One example:

panel.tskernel
 xyplot(sunspot.year) + layer(panel.tskernel(x, y, width = 20, 
    c = 3, col = 1, lwd = 2))   

horizonplot

Plot many time series in parallel

Usage, Details, Examples

One example:

horizonplot
 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

Trellis displays on Maps a.k.a. Choropleth maps

Usage, Details, Examples

One example:

mapplot
 mapplot(county ~ log10(population), ancestry, map = county.map, 
    colramp = NULL)   

tileplot

Plot a spatial mosaic from irregular 2D points

Usage, Details, Examples

One example:

tileplot
 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

Panel functions for level-coded irregular points

Usage, Details, Examples

One example:

panel.levelplot.points
 levelplot(depth ~ long + lat | Magnitude, data = quakes.ordered, 
    panel = panel.levelplot.points, type = c("p", "g"), aspect = "iso", 
    prepanel = prep....   

panel.2dsmoother

Plot a smooth approximation of z over x and y.

Usage, Details, Examples

One example:

panel.2dsmoother
 levelplot(z ~ x * y, xyz, panel = panel.levelplot.points, cex = 1.2) + 
    layer_(panel.2dsmoother(..., n = 200))   

dendrogramGrob

Create a Grob Representing a Dendrogram

Usage, Details, Examples

One example:

dendrogramGrob
 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

Put Strips on the Boundary of a Lattice Display

Usage, Details, Examples

One example:

useOuterStrips
 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

Resize panels to match data scales

Usage, Details, Examples

One example:

resizePanels
 dotplot(state.name ~ Frost | reorder(state.region, Frost), data = state, 
    layout = c(1, 4), scales = list(y = list(relation = "free")), 
    par.settings ....   

panel.ablineq

Draw a line with a label, by default its equation

Usage, Details, Examples

One example:

panel.ablineq
 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

Draw a scale bar as an arrow, labelled with its length in plot units.

Usage, Details, Examples

One example:

panel.scaleArrow
 xyplot(EuStockMarkets) + layer(panel.scaleArrow(x = 0.99, append = " units", 
    col = "grey", srt = 90, cex = 0.8))   

panel.3dmisc

Miscellanous panel utilities for three dimensional Trellis Displays

Usage, Details, Examples

One example:

panel.3dmisc
 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

Add layers to a Trellis plot, optionally using a new data source

Usage, Details, Examples

One example:

layer
 qua + layer_(panel.contourplot(x = gridlon, y = gridlat, z = dist, 
    contour = TRUE, subscripts = TRUE), data = newdat)   

as.layer

Overlay panels of Trellis plots on same or different scales

Usage, Details, Examples

One example:

as.layer
 xyplot(fdeaths ~ mdeaths) + as.layer(bwplot(~mdeaths, box.ratio = 0.2), 
    y.same = FALSE)   

doubleYScale

Draw two plot series with different y scales

Usage, Details, Examples

One example:

doubleYScale
 doubleYScale(obj1, obj2, add.ylab2 = TRUE)   

c.trellis

Merge trellis objects, using same or different scales

Usage, Details, Examples

One example:

c.trellis
 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

This is a sample plot to demonstrate different graphical settings (themes).

One example:

style 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

Create a lattice theme based on specified colors

Usage, Details, Examples

One example:

custom.theme
 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

Generate plots with style like The Economist.

Usage, Details, Examples

One example:

theEconomist.theme
 trellis.last.object() + layer_(panel.xblocks(x, x >= 1980, col = "#6CCFF6", 
    alpha = 0.5)) + layer(panel.text(1988, 180, "Forecast", font = 3, 
    pos = ....   

data

USAge

US national population estimates

Usage, Details, Examples

USCancerRates

Rate of Death Due to Cancer in US Counties

Usage, Details, Examples

ancestry

Modal ancestry by County according to US 2000 Census

Usage, Details, Examples

postdoc

Reasons for Taking First Postdoctoral Appointment

Usage, Details, Examples

One example:

postdoc
 barchart(prop.table(postdoc, margin = 1), auto.key = TRUE, xlab = "Proportion")   

biocAccess

Hourly access attempts to Bioconductor website

Usage, Details, Examples

One example:

biocAccess
 xyplot(stl(ts(biocAccess$counts[1:(24 * 30)], frequency = 24), 
    "periodic"), strip.left = strip.custom(horizontal = FALSE, 
    strip.names = FALSE, strip....   

gvhd10

Flow cytometry data from five samples from a patient

Usage, Details, Examples

SeatacWeather

Daily Rainfall and Temperature at the Seattle-Tacoma Airport

Usage, Details, Examples

EastAuClimate

Climate of the East Coast of Australia

Usage, Details, Examples

One example:

EastAuClimate
 segplot(siteNames ~ WinterMinTemp + SummerMaxTemp, EastAuClimate, 
    level = RainDays, sub = "Color scale: number of rainy days per year", 
    xlab = "Temp....   
latticeExtra version 0.6-6 on R version 2.11.0 (at 2010-02-05)

fonts by exljbris
web dev by felix andrews