clines {clines}R Documentation

Calculate Contour Lines

Description

Produces a list of contours. Each contour is a list of 3 elements: the contour level, the x-coordinates of the contour, and the y-coordinates of the contour.

Usage

clines(x, y, z, nlevels = 10, levels = pretty(range(z, na.rm = TRUE), nlevels))

Arguments

x,y locations of grid lines at which the values in z are measured. These must be in ascending order. By default, equally spaced values from 0 to 1 are used. If x is a list, its components x$x and x$y are used for x and y, respectively. If the list has component z this is used for z.
z a matrix containing the values to be plotted (NAs are allowed). Note that x can be used instead of z for convenience.
nlevels number of contour levels desired iff levels is not supplied.
levels numeric vector of levels at which to draw contour lines.

Value

A list of contours. Each contour consists of:

1 The contour level.
2 The x-coordinates of the contour.
3 The y-coordinates of the contour.

Warning

This function was just a temporary interface to the C code underlying the contour function. There is now a base function called contourLines which should be used instead.

Author(s)

Paul Murrell

Examples

# Mount Maungawhau
data("volcano")
rx <- range(x <- 10*1:nrow(volcano))
ry <- range(y <- 10*1:ncol(volcano))
ry <- ry + c(-1,1) * (diff(rx) - diff(ry))/2
tcol <- terrain.colors(12)
plot(x = 0, y = 0,type = "n", xlim = rx, ylim = ry, xlab = "", ylab = "")
u <- par("usr")
rect(u[1], u[3], u[2], u[4], col = tcol[8], border = "red")

line.list <- clines(x, y, volcano)

contour(x, y, volcano, col = tcol[2], lty = "solid", add = TRUE,
        vfont = c("sans serif", "plain"))

templines <- function(clines) {
  lines(clines[[2]], clines[[3]])
}  
invisible(lapply(line.list, templines))

[Package clines version 2.0-1 Index]