[R] plot.function with xlim, bug?
Prasenjit Kapat
kapatp at gmail.com
Thu Feb 1 20:43:10 CET 2007
Consider the following lines of code:
plot(function(x) sin(cos(x)*exp(-x/2)), from=-8,to=7,xlim=c(-5,5))
Uses integral points (integers from -5 to 5) to draw the plot, instead
of the usual default of n= 101 "equally spaced points" (from
?plot.function).
plot(function(x) sin(cos(x)*exp(-x/2)), from=-8,to=7,n=101,xlim=c(-5,5))
Gives the following error:
Error in add && par("xlog") : invalid 'x' type in 'x && y'
Any explanations? The following modification, in the plot.R by NOT
passing 'y' to plot.function, seems to fix both of the above problems
! I am sure to be missing something!
"plot2" <- function (x, y, ...)
{
if (is.null(attr(x, "class")) && is.function(x)) {
nms <- names(list(...))
## need to pass 'y' to plot.function() when positionally matched "????"
if(missing(y)) # set to defaults {could use formals(plot.default)}:
y <- { if (!"from" %in% nms) 0 else
if (!"to" %in% nms) 1 else
if (!"xlim" %in% nms) NULL }
if ("ylab" %in% nms)
plot.function(x, ...)
else
plot.function(x, ylab=paste(deparse(substitute(x)),"(x)"), ...)
}
else UseMethod("plot")
}
-------------------------------------------------------------------------------------------------------------------------------
version.string R version 2.4.1 (2006-12-18)
platform i486-pc-gnu-linux
More information about the R-help
mailing list