[R] Plot of function seems to cut off near edge of domain
Matthieu Dubois
matthdub at gmail.com
Tue Mar 27 09:31:52 CEST 2012
Dear Chad,
your problem is linked to (1) the function returning NaNs from x values
greater than 50, and (2) the fact that the function is estimated on a
predefined number of points.
Calling plot for a function object is basically a wrapper for curve(). Your
function g() is evaluated on the whole xlim domain, which will return NaN
values for x>50 (Try g(60) ). In addition, curve() splits the x interval (here
from 0 to 60) into a predifined number of points (n=101 is the default, see
help(curve)) at which the function is estimated. In your code, the function is
estimated at values x <- seq(0, 60, length=101), and g(x) that are not NaN are
plotted. The largest x value (from the sequence) that doesn't return a NaN is
max(x[!is.nan(g(x))]), which is 49.8.
One way to solve it is to explicitly specify the domain used to estimate the
function, by using the from and to arguments that are passed to curve():
#Figure 2, with xlim beyond the radius of the circle
plot(g,axes=F,from=0, to =50, xlim=c(0, 60), ylim=c(0,60))
axis(1,pos=0)
axis(2,pos=0)
HTH
Matthieu
Matthieu Dubois
Post-doctoral researcher
Psychology Department
Université Libre de Bruxelles
More information about the R-help
mailing list