The function or expression expr
(for magcurve
) or function
x
(for magplot
) is evaluated at n
points equally
spaced over the range [from, to]
. The points determined in
this way are then plotted.
If either from
or to
is NULL
, it defaults to the
corresponding element of xlim
if that is not NULL
.
What happens when neither from
/to
nor xlim
specifies both x-limits is a complex story. For
magplot(<function>)
and for magcurve(add = FALSE)
the defaults
are \((0, 1)\). For magcurve(add = NA)
and magcurve(add =
TRUE)
the defaults are taken from the x-limits used for the previous
plot. (This differs from versions of R prior to 2.14.0.)
The value of log
is used both to specify the plot axes (unless
add = TRUE
) 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.
The default value of log
is taken from the current plot when
add = TRUE
, whereas if add = NA
the x component is taken
from the existing plot (if any) and the y component defaults to
linear. For add = FALSE
the default is ""
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.
For expensive-to-compute expr
essions, you should use smarter tools.
The way magcurve
handles expr
has caused confusion. It
first looks to see if expr
is a name (also known as a
symbol), in which case it is taken to be the name of a function, and
expr
is replaced by a call to expr
with a single
argument with name given by xname
. Otherwise it checks that
expr
is either a call or an expression, and that
it contains a reference to the variable given by xname
(using
all.vars
): anything else is an error. Then expr
is evaluated in an environment which supplies a vector of name given
by xname
of length n
, and should evaluate to an object
of length n
. Note that this means that magcurve(x, ...)
is
taken as a request to plot a function named x
(and it is used
as such in the function
method for magplot
).