Learn R Programming

lattice (version 0.5-4)

levelplot: Level Plots

Description

Draw Level Plots and Contour plots.

Usage

levelplot(formula, data,
          at,
          col.regions = trellis.par.get("regions")$col,
          colorkey = region,
          contour = FALSE,
          cuts = 15,
          labels = format(at),
          pretty = FALSE,
          region = TRUE,
          ...)
contourplot(formula, data, at,
            contour = TRUE,
            cuts = 7,
            pretty = TRUE,
            ...)

Arguments

formula
a formula of the form z ~ x * y | g1 * g2 * ..., where z is a numeric response, and x, y are numeric values evaluated on a rectangular grid. g1,g2,..., if present, must be either factor
data
optional data frame in which variables are to be evaluated
at
numeric vector giving breaks along the range of z. Contours (if any) will be drawn at these heights, and the regions in between would be colored using col.regions.
col.regions
color vector to be used if regions is TRUE
colorkey
logical specifying whether a color key is to be drawn alongside the plot, or a list describing the color key. The list may contain the following components:

space location of the colorkey, can be one of ``left'', ``right'', `

contour
logical, whether to draw contour lines.
cuts
number of levels the range of z would be divided into
labels
character vector of labels for contour lines, not implemented yet.
pretty
logical, whether to use pretty labels
region
logical, whether regions between contour lines should be filled
...
other arguments

synopsis

levelplot(formula, data = parent.frame(), aspect = "fill", layout = NULL, panel = "panel.levelplot", prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, at, col.regions = terrain.colors(length(at) - 1), colorkey = NULL, contour = FALSE, cuts = 15, labels = format(at), pretty = FALSE, region = TRUE, ..., subscripts = TRUE, subset = TRUE) contourplot(formula, data = parent.frame(), aspect = "fill", layout = NULL, panel = "panel.levelplot", prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, cuts = 7, contour = TRUE, pretty = TRUE, region = FALSE, ..., subscripts = TRUE, subset = TRUE)

Details

These and all other high level Trellis functions have several arguments in common. These are extensively documented only in the help page for xyplot, which should be consulted to learn more detailed usage.

See Also

xyplot, Lattice, panel.levelplot

Examples

Run this code
x <- seq(pi/4, 5*pi, length = 100)
y <- seq(pi/4, 5*pi, length = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
levelplot(z~x*y, grid, cuts = 50, xlab="", ylab="",
          main="Weird Function", colorkey = FALSE)
levelplot(z~x*y, grid, cuts = 50, scales=list(log="e"), xlab="",
          ylab="", main="Weird Function", sub="with log scales",
          colorkey = FALSE, region = TRUE)
#S+ example
data(environmental)
attach(environmental)
ozo.m <- loess((ozone^(1/3)) ~ wind * temperature * radiation,
       parametric = c("radiation", "wind"), span = 1, degree = 2)
w.marginal <- seq(min(wind), max(wind), length = 50)
t.marginal <- seq(min(temperature), max(temperature), length = 50)
r.marginal <- seq(min(radiation), max(radiation), length = 4)
wtr.marginal <- list(wind = w.marginal, temperature = t.marginal,
        radiation = r.marginal)
grid <- expand.grid(wtr.marginal)
grid[, "fit"] <- c(predict(ozo.m, grid))
contourplot(fit ~ wind * temperature | radiation, data = grid,
          cuts = 10, region = TRUE,
          xlab = "Wind Speed (mph)",
          ylab = "Temperature (F)",
          main = "Cube Root Ozone (cube root ppb)",
          col.regions = trellis.par.get("regions")$col)
detach()

Run the code above in your browser using DataLab