Rev 41502 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{image}\alias{image}\alias{image.default}\title{Display a Color Image}\usage{image(x, \dots)\method{image}{default}(x, y, z, zlim, xlim, ylim, col = heat.colors(12),add = FALSE, xaxs = "i", yaxs = "i", xlab, ylab,breaks, oldstyle = FALSE, \dots)}\arguments{\item{x,y}{locations of grid lines at which the values in \code{z} aremeasured. These must be finite, non-missing and in (strictly)ascending order. By default, equallyspaced values from 0 to 1 are used. If \code{x} is a \code{list},its components \code{x$x} and \code{x$y} are used for \code{x}and \code{y}, respectively. If the list has component \code{z} thisis used for \code{z}.}\item{z}{a matrix containing the values to be plotted (\code{NA}s areallowed). Note that \code{x} can be used instead of \code{z} forconvenience.}\item{zlim}{the minimum and maximum \code{z} values for which colorsshould be plotted, defaulting to the range of the finite values of\code{z}. Each of the given colors will be used to color anequispaced interval of this range. The \emph{midpoints} of theintervals cover the range, so that values just outside the rangewill be plotted.}\item{xlim, ylim}{ranges for the plotted \code{x} and \code{y} values,defaulting to the ranges of \code{x} and \code{y}.}\item{col}{a list of colors such as that generated by\code{\link{rainbow}}, \code{\link{heat.colors}},\code{\link{topo.colors}}, \code{\link{terrain.colors}} or similarfunctions.}\item{add}{logical; if \code{TRUE}, add to current plot (and disregardthe following arguments). This is rarely useful because\code{image} \dQuote{paints} over existing graphics.}\item{xaxs, yaxs}{style of x and y axis. The default \code{"i"} isappropriate for images. See \code{\link{par}}.}\item{xlab, ylab}{each a character string giving the labels for the x andy axis. Default to the \sQuote{call names} of \code{x} or \code{y}, or to\code{""} if these were unspecified.}\item{breaks}{a set of breakpoints for the colours: must give one morebreakpoint than colour.}\item{oldstyle}{logical. If true the midpoints of the colour intervalsare equally spaced, and \code{zlim[1]} and \code{zlim[2]} were takento be midpoints. The default is to have colour intervals of equallengths between the limits.}\item{\dots}{graphical parameters for \code{\link{plot}} may also bepassed as arguments to this function, as can the plot aspect ratio\code{asp} and \code{axes} (see \code{\link{plot.window}}).}}\description{Creates a grid of colored or gray-scale rectangles with colorscorresponding to the values in \code{z}. This can be used to displaythree-dimensional or spatial data aka \dQuote{images}.This is a generic function.The functions \code{\link{heat.colors}}, \code{\link{terrain.colors}}and \code{\link{topo.colors}} create heat-spectrum (red to white) andtopographical color schemes suitable for displaying ordered data, with\code{n} giving the number of colors desired.}\details{The length of \code{x} should be equal to the \code{nrow(z)+1} or\code{nrow(z)}. In the first case \code{x} specifies the boundariesbetween the cells: in the second case \code{x} specifies the midpointsof the cells. Similar reasoning applies to \code{y}. It probablyonly makes sense to specify the midpoints of an equally-spacedgrid. If you specify just one row or column and a length-one \code{x}or \code{y}, the whole user area in the corresponding direction isfilled.Rectangles corresponding to missing values are not plotted (and so aretransparent and (unless \code{add=TRUE}) the default background paintedin \code{par("bg")} will show though and if that is transparent, thecanvas colour will be seen).If \code{breaks} is specified then \code{zlim} is unused and thealgorithm used follows \code{\link{cut}}, so intervals are closed onthe right and open on the left except for the lowest interval.Notice that \code{image} interprets the \code{z} matrix as a table of\code{f(x[i], y[j])} values, so that the x axis corresponds to rownumber and the y axis to column number, with column 1 at the bottom,i.e. a 90 degree counter-clockwise rotation of the conventionalprinted layout of a matrix.}\note{Based on a function by Thomas Lumley\email{tlumley@u.washington.edu}.}\seealso{\code{\link{filled.contour}} or \code{\link{heatmap}} which canlook nicer (but are less modular),\code{\link{contour}};The \pkg{lattice} equivalent of \code{image} is\code{\link[lattice]{levelplot}}.\code{\link{heat.colors}}, \code{\link{topo.colors}},\code{\link{terrain.colors}}, \code{\link{rainbow}},\code{\link{hsv}}, \code{\link{par}}.}\examples{require(grDevices) # for coloursx <- y <- seq(-4*pi, 4*pi, len=27)r <- sqrt(outer(x^2, y^2, "+"))image(z = z <- cos(r^2)*exp(-r/6), col=gray((0:32)/32))image(z, axes = FALSE, main = "Math can be beautiful ...",xlab = expression(cos(r^2) * e^{-r/6}))contour(z, add = TRUE, drawlabels = FALSE)# Volcano data visualized as matrix. Need to transpose and flip# matrix horizontally.image(t(volcano)[ncol(volcano):1,])# A prettier display of the volcanox <- 10*(1:nrow(volcano))y <- 10*(1:ncol(volcano))image(x, y, volcano, col = terrain.colors(100), axes = FALSE)contour(x, y, volcano, levels = seq(90, 200, by = 5),add = TRUE, col = "peru")axis(1, at = seq(100, 800, by = 100))axis(2, at = seq(100, 600, by = 100))box()title(main = "Maunga Whau Volcano", font.main = 4)}\keyword{hplot}\keyword{aplot}