EVOLUTION-MANAGER
Edit File: contour.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Display Contours</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for contour {graphics}"><tr><td>contour {graphics}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Display Contours</h2> <h3>Description</h3> <p>Create a contour plot, or add contour lines to an existing plot. </p> <h3>Usage</h3> <pre> contour(x, ...) ## Default S3 method: contour(x = seq(0, 1, length.out = nrow(z)), y = seq(0, 1, length.out = ncol(z)), z, nlevels = 10, levels = pretty(zlim, nlevels), labels = NULL, xlim = range(x, finite = TRUE), ylim = range(y, finite = TRUE), zlim = range(z, finite = TRUE), labcex = 0.6, drawlabels = TRUE, method = "flattest", vfont, axes = TRUE, frame.plot = axes, col = par("fg"), lty = par("lty"), lwd = par("lwd"), add = FALSE, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, y</code></td> <td> <p>locations of grid lines at which the values in <code>z</code> are measured. These must be in ascending order. By default, equally spaced values from 0 to 1 are used. If <code>x</code> is a <code>list</code>, its components <code>x$x</code> and <code>x$y</code> are used for <code>x</code> and <code>y</code>, respectively. If the list has component <code>z</code> this is used for <code>z</code>.</p> </td></tr> <tr valign="top"><td><code>z</code></td> <td> <p>a matrix containing the values to be plotted (<code>NA</code>s are allowed). Note that <code>x</code> can be used instead of <code>z</code> for convenience.</p> </td></tr> <tr valign="top"><td><code>nlevels</code></td> <td> <p>number of contour levels desired <b>iff</b> <code>levels</code> is not supplied.</p> </td></tr> <tr valign="top"><td><code>levels</code></td> <td> <p>numeric vector of levels at which to draw contour lines.</p> </td></tr> <tr valign="top"><td><code>labels</code></td> <td> <p>a vector giving the labels for the contour lines. If <code>NULL</code> then the levels are used as labels, otherwise this is coerced by <code><a href="../../base/html/character.html">as.character</a></code>.</p> </td></tr> <tr valign="top"><td><code>labcex</code></td> <td> <p><code>cex</code> for contour labelling. This is an absolute size, not a multiple of <code>par("cex")</code>.</p> </td></tr> <tr valign="top"><td><code>drawlabels</code></td> <td> <p>logical. Contours are labelled if <code>TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>method</code></td> <td> <p>character string specifying where the labels will be located. Possible values are <code>"simple"</code>, <code>"edge"</code> and <code>"flattest"</code> (the default). See the ‘Details’ section.</p> </td></tr> <tr valign="top"><td><code>vfont</code></td> <td> <p>if <code>NULL</code>, the current font family and face are used for the contour labels. If a character vector of length 2 then Hershey vector fonts are used for the contour labels. The first element of the vector selects a typeface and the second element selects a fontindex (see <code><a href="text.html">text</a></code> for more information). The default is <code>NULL</code> on graphics devices with high-quality rotation of text and <code>c("sans serif", "plain")</code> otherwise.</p> </td></tr> <tr valign="top"><td><code>xlim, ylim, zlim</code></td> <td> <p>x-, y- and z-limits for the plot.</p> </td></tr> <tr valign="top"><td><code>axes, frame.plot</code></td> <td> <p>logical indicating whether axes or a box should be drawn, see <code><a href="plot.default.html">plot.default</a></code>.</p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>color for the lines drawn.</p> </td></tr> <tr valign="top"><td><code>lty</code></td> <td> <p>line type for the lines drawn.</p> </td></tr> <tr valign="top"><td><code>lwd</code></td> <td> <p>line width for the lines drawn.</p> </td></tr> <tr valign="top"><td><code>add</code></td> <td> <p>logical. If <code>TRUE</code>, add to a current plot.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>additional arguments to <code><a href="plot.window.html">plot.window</a></code>, <code><a href="title.html">title</a></code>, <code><a href="zAxis.html">Axis</a></code> and <code><a href="box.html">box</a></code>, typically <a href="par.html">graphical parameters</a> such as <code>cex.axis</code>.</p> </td></tr> </table> <h3>Details</h3> <p><code>contour</code> is a generic function with only a default method in base <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>. </p> <p>The methods for positioning the labels on contours are <code>"simple"</code> (draw at the edge of the plot, overlaying the contour line), <code>"edge"</code> (draw at the edge of the plot, embedded in the contour line, with no labels overlapping) and <code>"flattest"</code> (draw on the flattest section of the contour, embedded in the contour line, with no labels overlapping). The second and third may not draw a label on every contour line. </p> <p>For information about vector fonts, see the help for <code><a href="text.html">text</a></code> and <code><a href="../../grDevices/html/Hershey.html">Hershey</a></code>. </p> <p>Notice that <code>contour</code> interprets the <code>z</code> matrix as a table of <code>f(x[i], y[j])</code> values, so that the x axis corresponds to row number and the y axis to column number, with column 1 at the bottom, i.e. a 90 degree counter-clockwise rotation of the conventional textual layout. </p> <p>Alternatively, use <code><a href="../../lattice/html/levelplot.html">contourplot</a></code> from the <a href="https://CRAN.R-project.org/package=lattice"><span class="pkg">lattice</span></a> package where the <code><a href="../../stats/html/formula.html">formula</a></code> notation allows to use vectors <code>x</code>, <code>y</code>, and <code>z</code> of the same length. </p> <p>There is limited control over the axes and frame as arguments <code>col</code>, <code>lwd</code> and <code>lty</code> refer to the contour lines (rather than being general <a href="par.html">graphical parameters</a>). For more control, add contours to a plot, or add axes and frame to a contour plot. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="../../base/html/options.html">options</a>("max.contour.segments")</code> for the maximal complexity of a single contour line. </p> <p><code><a href="../../grDevices/html/contourLines.html">contourLines</a></code>, <code><a href="filled.contour.html">filled.contour</a></code> for color-filled contours, <code><a href="../../lattice/html/levelplot.html">contourplot</a></code> (and <code><a href="../../lattice/html/levelplot.html">levelplot</a></code>) from package <a href="https://CRAN.R-project.org/package=lattice"><span class="pkg">lattice</span></a>. Further, <code><a href="image.html">image</a></code> and the graphics demo which can be invoked as <code>demo(graphics)</code>. </p> <h3>Examples</h3> <pre> require(grDevices) # for colours x <- -6:16 op <- par(mfrow = c(2, 2)) contour(outer(x, x), method = "edge", vfont = c("sans serif", "plain")) z <- outer(x, sqrt(abs(x)), FUN = "/") image(x, x, z) contour(x, x, z, col = "pink", add = TRUE, method = "edge", vfont = c("sans serif", "plain")) contour(x, x, z, ylim = c(1, 6), method = "simple", labcex = 1, xlab = quote(x[1]), ylab = quote(x[2])) contour(x, x, z, ylim = c(-6, 6), nlev = 20, lty = 2, method = "simple", main = "20 levels; \"simple\" labelling method") par(op) ## Persian Rug Art: x <- y <- seq(-4*pi, 4*pi, len = 27) r <- sqrt(outer(x^2, y^2, "+")) opar <- par(mfrow = c(2, 2), mar = rep(0, 4)) for(f in pi^(0:3)) contour(cos(r^2)*exp(-r/f), drawlabels = FALSE, axes = FALSE, frame = TRUE) 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) par(opar); opar <- par(pty = "s", bg = "lightcyan") 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") contour(x, y, volcano, col = tcol[2], lty = "solid", add = TRUE, vfont = c("sans serif", "plain")) title("A Topographic Map of Maunga Whau", font = 4) abline(h = 200*0:4, v = 200*0:4, col = "lightgray", lty = 2, lwd = 0.1) ## contourLines produces the same contour lines as contour 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") contour(x, y, volcano, col = tcol[1], lty = "solid", add = TRUE, vfont = c("sans serif", "plain")) line.list <- contourLines(x, y, volcano) invisible(lapply(line.list, lines, lwd=3, col=adjustcolor(2, .3))) par(opar) </pre> <hr /><div style="text-align: center;">[Package <em>graphics</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>