EVOLUTION-MANAGER
Edit File: curve.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: Draw Function Plots</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 curve {graphics}"><tr><td>curve {graphics}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Draw Function Plots</h2> <h3>Description</h3> <p>Draws a curve corresponding to a function over the interval <code>[from, to]</code>. <code>curve</code> can plot also an expression in the variable <code>xname</code>, default <span class="samp">x</span>. </p> <h3>Usage</h3> <pre> curve(expr, from = NULL, to = NULL, n = 101, add = FALSE, type = "l", xname = "x", xlab = xname, ylab = NULL, log = NULL, xlim = NULL, ...) ## S3 method for class 'function' plot(x, y = 0, to = 1, from = y, xlim = NULL, ylab = NULL, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>expr</code></td> <td> <p>The name of a function, or a <a href="../../base/html/call.html">call</a> or an <a href="../../base/html/expression.html">expression</a> written as a function of <code>x</code> which will evaluate to an object of the same length as <code>x</code>.</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>a ‘vectorizing’ numeric <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> function.</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>alias for <code>from</code> for compatibility with <code>plot</code></p> </td></tr> <tr valign="top"><td><code>from, to</code></td> <td> <p>the range over which the function will be plotted.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>integer; the number of x values at which to evaluate.</p> </td></tr> <tr valign="top"><td><code>add</code></td> <td> <p>logical; if <code>TRUE</code> add to an already existing plot; if <code>NA</code> start a new plot taking the defaults for the limits and log-scaling of the x-axis from the previous plot. Taken as <code>FALSE</code> (with a warning if a different value is supplied) if no graphics device is open.</p> </td></tr> <tr valign="top"><td><code>xlim</code></td> <td> <p><code>NULL</code> or a numeric vector of length 2; if non-<code>NULL</code> it provides the defaults for <code>c(from, to)</code> and, unless <code>add = TRUE</code>, selects the x-limits of the plot – see <code><a href="plot.window.html">plot.window</a></code>.</p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>plot type: see <code><a href="plot.default.html">plot.default</a></code>.</p> </td></tr> <tr valign="top"><td><code>xname</code></td> <td> <p>character string giving the name to be used for the x axis.</p> </td></tr> <tr valign="top"><td><code>xlab, ylab, log, ...</code></td> <td> <p>labels and <a href="par.html">graphical parameters</a> can also be specified as arguments. See ‘Details’ for the interpretation of the default for <code>log</code>. </p> <p>For the <code>"function"</code> method of <code>plot</code>, <code>...</code> can include any of the other arguments of <code>curve</code>, except <code>expr</code>. </p> </td></tr> </table> <h3>Details</h3> <p>The function or expression <code>expr</code> (for <code>curve</code>) or function <code>x</code> (for <code>plot</code>) is evaluated at <code>n</code> points equally spaced over the range <code>[from, to]</code>. The points determined in this way are then plotted. </p> <p>If either <code>from</code> or <code>to</code> is <code>NULL</code>, it defaults to the corresponding element of <code>xlim</code> if that is not <code>NULL</code>. </p> <p>What happens when neither <code>from</code>/<code>to</code> nor <code>xlim</code> specifies both x-limits is a complex story. For <code>plot(<function>)</code> and for <code>curve(add = FALSE)</code> the defaults are <i>(0, 1)</i>. For <code>curve(add = NA)</code> and <code>curve(add = TRUE)</code> the defaults are taken from the x-limits used for the previous plot. (This differs from versions of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> prior to 2.14.0.) </p> <p>The value of <code>log</code> is used both to specify the plot axes (unless <code>add = TRUE</code>) and how ‘equally spaced’ is interpreted: if the x component indicates log-scaling, the points at which the expression or function is plotted are equally spaced on log scale. </p> <p>The default value of <code>log</code> is taken from the current plot when <code>add = TRUE</code>, whereas if <code>add = NA</code> the x component is taken from the existing plot (if any) and the y component defaults to linear. For <code>add = FALSE</code> the default is <code>""</code> </p> <p>This used to be a quick hack which now seems to serve a useful purpose, but can give bad results for functions which are not smooth. </p> <p>For expensive-to-compute <code>expr</code>essions, you should use smarter tools. </p> <p>The way <code>curve</code> handles <code>expr</code> has caused confusion. It first looks to see if <code>expr</code> is a <a href="../../base/html/name.html">name</a> (also known as a symbol), in which case it is taken to be the name of a function, and <code>expr</code> is replaced by a call to <code>expr</code> with a single argument with name given by <code>xname</code>. Otherwise it checks that <code>expr</code> is either a <a href="../../base/html/call.html">call</a> or an <a href="../../base/html/expression.html">expression</a>, and that it contains a reference to the variable given by <code>xname</code> (using <code><a href="../../base/html/allnames.html">all.vars</a></code>): anything else is an error. Then <code>expr</code> is evaluated in an environment which supplies a vector of name given by <code>xname</code> of length <code>n</code>, and should evaluate to an object of length <code>n</code>. Note that this means that <code>curve(x, ...)</code> is taken as a request to plot a function named <code>x</code> (and it is used as such in the <code>function</code> method for <code>plot</code>). </p> <p>The <code>plot</code> method can be called directly as <code>plot.function</code>. </p> <h3>Value</h3> <p>A list with components <code>x</code> and <code>y</code> of the points that were drawn is returned invisibly. </p> <h3>Warning</h3> <p>For historical reasons, <code>add</code> is allowed as an argument to the <code>"function"</code> method of <code>plot</code>, but its behaviour may surprise you. It is recommended to use <code>add</code> only with <code>curve</code>. </p> <h3>See Also</h3> <p><code><a href="../../stats/html/splinefun.html">splinefun</a></code> for spline interpolation, <code><a href="lines.html">lines</a></code>. </p> <h3>Examples</h3> <pre> plot(qnorm) # default range c(0, 1) is appropriate here, # but end values are -/+Inf and so are omitted. plot(qlogis, main = "The Inverse Logit : qlogis()") abline(h = 0, v = 0:2/2, lty = 3, col = "gray") curve(sin, -2*pi, 2*pi, xname = "t") curve(tan, xname = "t", add = NA, main = "curve(tan) --> same x-scale as previous plot") op <- par(mfrow = c(2, 2)) curve(x^3 - 3*x, -2, 2) curve(x^2 - 2, add = TRUE, col = "violet") ## simple and advanced versions, quite similar: plot(cos, -pi, 3*pi) curve(cos, xlim = c(-pi, 3*pi), n = 1001, col = "blue", add = TRUE) chippy <- function(x) sin(cos(x)*exp(-x/2)) curve(chippy, -8, 7, n = 2001) plot (chippy, -8, -5) for(ll in c("", "x", "y", "xy")) curve(log(1+x), 1, 100, log = ll, sub = paste0("log = '", ll, "'")) par(op) </pre> <hr /><div style="text-align: center;">[Package <em>graphics</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>