Rev 5415 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{B_06_levelplot}\title{Level plots and contour plots}\alias{levelplot}\alias{contourplot}\alias{levelplot.formula}\alias{contourplot.formula}\alias{levelplot.table}\alias{contourplot.table}\alias{levelplot.array}\alias{contourplot.array}\alias{levelplot.matrix}\alias{contourplot.matrix}\usage{levelplot(x, data, \dots)contourplot(x, data, \dots)\method{levelplot}{formula}(x,data,allow.multiple = is.null(groups) || outer,outer = TRUE,aspect = "fill",panel = lattice.getOption("panel.levelplot"),prepanel = NULL,scales = list(),strip = TRUE,groups = NULL,xlab,xlim,ylab,ylim,at,cuts = 15,pretty = FALSE,region = TRUE,drop.unused.levels = lattice.getOption("drop.unused.levels"),\dots,lattice.options = NULL,default.scales = list(),colorkey = region,col.regions,alpha.regions,subset = TRUE)\method{contourplot}{formula}(x,data,panel = lattice.getOption("panel.contourplot"),cuts = 7,labels = TRUE,contour = TRUE,pretty = TRUE,region = FALSE,\dots)\method{levelplot}{table}(x, data = NULL, aspect = "iso", \dots, xlim, ylim)\method{contourplot}{table}(x, data = NULL, aspect = "iso", \dots, xlim, ylim)\method{levelplot}{matrix}(x, data = NULL, aspect = "iso",\dots, xlim, ylim,row.values = seq_len(nrow(x)),column.values = seq_len(ncol(x)))\method{contourplot}{matrix}(x, data = NULL, aspect = "iso",\dots, xlim, ylim,row.values = seq_len(nrow(x)),column.values = seq_len(ncol(x)))\method{levelplot}{array}(x, data = NULL, \dots)\method{contourplot}{array}(x, data = NULL, \dots)}\description{Draw Level Plots and Contour plots.}\arguments{\item{x}{for the \code{formula} method, a formula of the form \code{z ~ x * y| g1 * g2 * \dots}, where \code{z} is a numeric response, and\code{x}, \code{y} are numeric values evaluated on a rectangulargrid. \code{g1, g2, \dots} are optional conditional variables, andmust be either factors or shingles if present.Calculations are based on the assumption that all x and y values areevaluated on a grid (defined by their unique values). The functionwill not return an error if this is not true, but the display mightnot be meaningful. However, the x and y values need not be equallyspaced.Both \code{levelplot} and \code{wireframe} have methods for\code{matrix}, \code{array}, and \code{table} objects, in which case\code{x} provides the \code{z} vector described above, while itsrows and columns are interpreted as the \code{x} and \code{y}vectors respectively. This is similar to the form used in\code{filled.contour} and \code{image}. For higher-dimensionalarrays and tables, further dimensions are used as conditioningvariables. Note that the dimnames may be duplicated; this ishandled by calling \code{\link{make.unique}} to make the namesunique (although the original labels are used for the x- andy-axes).}\item{data}{For the \code{formula} methods, an optional data frame in whichvariables in the formula (as well as \code{groups} and\code{subset}, if any) are to be evaluated. Usually ignored with awarning in other cases.}\item{row.values, column.values}{ Optional vectors of values thatdefine the grid when \code{x} is a matrix. \code{row.values} and\code{column.values} must have the same lengths as \code{nrow(x)}and \code{ncol(x)} respectively. By default, row and columnnumbers. }\item{panel}{panel function used to create the display, as described in\code{\link{xyplot}}}\item{aspect}{For the \code{matrix} methods, the default aspect ratio is chosen tomake each cell square. The usual default is \code{aspect="fill"},as described in \code{\link{xyplot}}.}\item{at}{numeric vector giving breakpoints along the range of\code{z}. Contours (if any) will be drawn at these heights, and theregions in between would be colored using \code{col.regions}. Inthe latter case, values outside the range of \code{at} will not bedrawn at all. This serves as a way to limit the range of the datashown, similar to what a \code{zlim} argument might have been usedfor. However, this also means that when supplying \code{at}explicitly, one has to be careful to include values outside therange of \code{z} to ensure that all the data are shown.}\item{col.regions}{ color vector to be used if regions is TRUE. Thegeneral idea is that this should be a color vector of moderatelylarge length (longer than the number of regions. By default this is100). It is expected that this vector would be gradually varying incolor (so that nearby colors would be similar). When the colors areactually chosen, they are chosen to be equally spaced along thisvector. When there are more regions than colors in\code{col.regions}, the colors are recycled. The actual colorassignment is performed by \code{\link{level.colors}}, which isdocumented separately.}\item{alpha.regions}{numeric, specifying alpha transparency (works only on some devices)}\item{colorkey}{logical specifying whether a color key is to be drawnalongside the plot, or a list describing the color key. The list maycontain the following components:\describe{\item{\code{space}:}{location of the colorkey, can be one of \code{"left"},\code{"right"}, \code{"top"} and \code{"bottom"}. Defaults to\code{"right"}.}\item{\code{x}, \code{y}:}{ location, currently unused }\item{\code{col}:}{ vector of colors }\item{\code{at}:}{numeric vector specifying where the colors change. must be oflength 1 more than the col vector.}\item{\code{labels}:}{a character vector for labelling the \code{at} values, or morecommonly, a list describing characteristics of the labels. Thislist may include components \code{labels}, \code{at},\code{cex}, \code{col}, \code{rot}, \code{font}, \code{fontface}and \code{fontfamily}.}\item{\code{tick.number}:}{ approximate number of ticks. }\item{\code{corner}:}{ interacts with x, y; unimplemented }\item{\code{width}:}{ width of the key }\item{\code{height}:}{ length of key w.r.t side of plot. }}}\item{contour}{logical, whether to draw contour lines.}\item{cuts}{number of levels the range of \code{z} would be divided into}\item{labels}{typically a logical indicating whether contour lines should belabelled, but other possibilities for more sophisticated controlexists. Details are documented in the help page for\code{\link{panel.levelplot}}, to which this argument is passed onunchanged. That help page also documents the \code{label.style}argument, which affects how the labels are rendered.}\item{pretty}{logical, whether to use pretty cut locations and labels}\item{region}{logical, whether regions between contour lines should be filled}\item{allow.multiple, outer, prepanel, scales, strip, groups, xlab,xlim, ylab, ylim, drop.unused.levels, lattice.options,default.scales, subset}{these arguments are described in the help page for\code{\link{xyplot}}.}\item{\dots}{ other arguments. Some are processed by \code{levelplot}or \code{contourplot}, and those unrecognized are passed on to thepanel function. }}\details{These and all other high level Trellis functions have severalarguments in common. These are extensively documented only in thehelp page for \code{xyplot}, which should be consulted to learn moredetailed usage.Other useful arguments are mentioned in the help page for the defaultpanel function \code{\link{panel.levelplot}} (these are formallyarguments to the panel function, but can be specified in the highlevel calls directly).}\references{Sarkar, Deepayan (2008) "Lattice: Multivariate Data Visualization withR", Springer. \url{http://lmdvr.r-forge.r-project.org/}}\value{An object of class \code{"trellis"}. The\code{\link[lattice:update.trellis]{update}} method can be used toupdate components of the object and the\code{\link[lattice:print.trellis]{print}} method (usually called bydefault) will plot it on an appropriate plotting device.}\seealso{\code{\link{xyplot}}, \code{\link{Lattice}},\code{\link{panel.levelplot}}}\author{Deepayan Sarkar \email{Deepayan.Sarkar@R-project.org}}\examples{x <- seq(pi/4, 5 * pi, length.out = 100)y <- seq(pi/4, 5 * pi, length.out = 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, scales=list(log="e"), xlab="",ylab="", main="Weird Function", sub="with log scales",colorkey = FALSE, region = TRUE)#S-PLUS examplerequire(stats)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.out = 50)t.marginal <- seq(min(temperature), max(temperature), length.out = 50)r.marginal <- seq(min(radiation), max(radiation), length.out = 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)")detach()}\keyword{hplot}