prep4image: Prepares data frame for plotting with image/contour/persp.

Description Usage Arguments Details Examples

Description

From an input data frame with columns x, y and z, this function creates a list with elements x, y and z in a format suitable for passing to functions image, contour or persp. The coordinates in data are assumed to come from a 2D grid of points.

Usage

1

Arguments

data

a data frame with columns x and y being Cartesian coordinates, and z being the values of some variable at each coordinate.

plot

if TRUE then an image plot will be drawn using image.plot

contour

if TRUE then contours will be added (only used when plot=TRUE)

key

logical for whether or not to include key when plot = TRUE (image.plot is used when key = TRUE, image is used when key = FALSE)

...

other arguments to pass to image or image.plot (only used when plot=TRUE)

Details

Sorts z on values of x first, then y, then creates a matrix of z-values from this. Returns a list with elements x (unique values of x, in increasing order), y (unique values of y, in increasing order) and z (matrix of z-values in appropriate order for image/contour/persp).

If the original z is a factor variabele, the z returned is a matrix of integers between 1 and length(levels(z)) and the output list has an attributes called “facnames” that is a character vector containing the levels as factor variables, with z=1 corresponding to the first name, z=2 to the second, etc.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
data(Boland.alt)
op = par(no.readonly = TRUE)
par(mfrow = c(1,1))

# make object for use with image
imagedata = prep4image(Boland.alt, plot = FALSE)
image(imagedata, asp = 1)
contour(imagedata, add = TRUE)

# use directly for plotting
prep4image(Boland.alt, asp = 1)
prep4image(Boland.alt, asp = 1, contour = FALSE)
prep4image(Boland.alt, asp = 1, key = FALSE)
prep4image(Boland.alt, asp = 1, contour = FALSE, key = FALSE)

par(op)

david-borchers/secrgam documentation built on May 14, 2019, 9:30 p.m.