Learn R Programming

npsp (version 0.3-6)

rgraphics: R Graphics for gridded data

Description

Draw an image, perspective, contour or filled contour plot for data on a bidimensional regular grid (S3 methods for class "codedata.grid").

Usage

"image" (x, data.ind = 1, xlab = NULL, ylab = NULL, ...)
"persp" (x, data.ind = 1, xlab = NULL, ylab = NULL, zlab = NULL, ...)
"contour" (x, data.ind = 1, filled = FALSE, xlab = NULL, ylab = NULL, ...)

Arguments

x
a "codedata.grid"-class object.
data.ind
integer or character with the index or name of the component containing the values to be used for coloring the rectangles.
xlab
label for the x axis, defaults to dimnames(x)[1].
ylab
label for the y axis, defaults to dimnames(x)[2].
zlab
label for the z axis, defaults to names(x)[data.ind].
...
additional graphical parameters (to be passed to main plot function).
filled
logical; if FALSE (default), function contour is called, otherwise filled.contour.

See Also

image, persp, contour, filled.contour, data.grid.

Examples

Run this code
# Regularly spaced 2D data
grid <- grid.par(n = c(50, 50), min = c(-1, -1), max = c(1, 1))

f2d <- function(x) x[1]^2 - x[2]^2
trend <- apply(coords(grid), 1, f2d)
set.seed(1)
y <- trend + rnorm(prod(dim(grid)), 0, 0.1)
gdata <- data.grid(trend = trend, y = y, grid = grid)

# perspective plot
persp(gdata, main = 'Trend', theta = 40, phi = 20, ticktype = "detailed")

# filled contour plot
contour(gdata, main = 'Trend', filled = TRUE, color.palette = jet.colors)

# Multiple plots with a common legend:
scale.range <- c(-1.2, 1.2)
scale.color <- jet.colors(64)
# 1x2 plot with some room for the legend...
old.par <- par(mfrow = c(1,2), omd = c(0.05, 0.85, 0.05, 0.95))
image(gdata, zlim = scale.range, main = 'Trend', col = scale.color)
contour(gdata, add = TRUE)
image(gdata, 'y', zlim = scale.range, main = 'Data', col = scale.color)
contour(gdata, 'y', add = TRUE)
par(old.par)
# the legend can be added to any plot...
splot(slim = scale.range, col = scale.color, add = TRUE)

Run the code above in your browser using DataLab