

   curve {base}                                 R Documentation

   DDrraaww FFuunnccttiioonn PPlloottss

   DDeessccrriippttiioonn::

        Draws a curve corresponding to the given function or
        expression (in `x') over the interval `[from,to]'.

   UUssaaggee::

        curve(expr, from, to, n = 101, add = FALSE, type = "l",
              ylab = NULL, log = NULL, ...)
        plot.function(fn, from = 0, to = 1, n = 101, ...)

   AArrgguummeennttss::

       expr: an expression written as a function of `x', or
             alternatively a function which will be plotted.

         fn: a `vectorizing' numeric R function.

    from,to: the range over which the function will be plotted.

          n: integer; the number of x values at which to evalu-
             ate.

        add: logical; if `TRUE' add to already existing plot.

        ...: graphical parameters can also be specified as
             arguments.  `plot.function' passes all these to
             `curve'.

   DDeettaaiillss::

        The evaluation of `expr' is at `n' points equally
        spaced over the range `[from, to]'.  The points deter-
        mined in this way are then joined with straight lines.
        `fn(x)' or `expr' (with `x' inside) must return a
        numeric of the same length as `x'.

        This used to be a quick hack which seems to serve a
        useful purpose, but can give bad results for functions
        which are not smooth.

   VVaalluuee::

        `NULL'. For ``expensive'' `expr'essions, you should use
        smarter tools.

   SSeeee AAllssoo::

        `splinefun' for spline interpolation, `lines'.

   EExxaammpplleess::

        par(mfrow=c(2,2))
        curve(x^3-3*x, -2, 2)
        curve(x^2-2, add = TRUE, col = "violet")

        curve(sin, -pi, 3*pi)
        plot(cos)
        chippy <- function(x) sin(cos(x)*exp(-x/2))
        curve(chippy, -8, 7, n=2001)

        for(ll in c("","x","y","xy"))
           curve(log(1+x), 1,100, log=ll, sub=paste("log=",ll))

