This function is generic (see Methods); method functions can be written to handle specific classes of data. Classes which already have methods for this function include: rsm.lm
contour(x, ...) contour.default(x, y, z, nlevels=5, levels=pretty(z, nlevels), add=F, labex=1, save=F, plotit=!save, triangles=F)
The first argument may be a list with components x, y, and z. In particular, the result of interp is suitable as an argument to contour.
If the first argument is a matrix, it is assumed to be the z matrix and vectors x and y are generated (x is 1:nrow(z), y is 1:ncol(z)). The result of predict together with expand.grid is suitable as an argument to contour.
Graphical parameters may also be supplied as arguments to this function (see par). The default x and y axis labels are generated from the names of the data; set xlab and ylab to "" to get no labels. In addition, the high-level graphics arguments described under par and the arguments to title may be supplied to this function.
If save is TRUE, then the output structure will be a list whose length is the number of contour intervals. The names of the elements will be the contour levels. Each component of this list will contain an x and y component suitable for plotting with lines.
Each rectangular cell of 4 numbers is contoured independently. If triangles is FALSE (the default), contour segments will connect the edges of the cell crossing the contour level. At saddle point cells (all 4 edges cross a contour level), we use the triangle method to select which edges to connect.
If triangles is TRUE, then the cell is broken up into 4 triangles meeting at the center and the z value at the center is set to be the average of the (non-missing) corner values. Then we fit a plane to each triangle and contour that with straight line segments. (Triangles with missing values at the corners are ignored.)
cont.lines <- contour(x, y, z, save=T) plot(x, y, type="n") for (j in seq(along=cont.lines)) if (length(cont.lines[[j]]$x)) lines(cont.lines[[j]])rx <- range(ozone.xy$x) ry <- range(ozone.xy$y) i <- interp(ozone.xy$x, ozone.xy$y, ozone.median) #interp creates a matrix of interpolated points, z, for # an increasing, evenly spaced sequence of points # over the range of the input x and y usa(xlim=rx, ylim=ry, lty=2, col=2) contour(i, add=T, labex=0) text(ozone.xy, ozone.median) title(main="Median Ozone in the North East")