[R] problems with plot()
Duncan Murdoch
murdoch.duncan at gmail.com
Tue Jul 20 03:12:05 CEST 2010
On 19/07/2010 5:47 PM, math_daddy wrote:
> I have a list of vectors of length 2, each representing a point in 2-space,
> and each of which I wish to plot on the current plot.
> In a loop, I assign the x and y coordinates of the current element of the
> list to variables 'x' and 'y' respectively, then make a call to plot as
> follows:
>
> par(new = TRUE)
> plot(x,y, xlim = c(0,1),ylim=c(0,1), xlab <- "x", ylab <- "y",type =
> "p",log="")
That's not the right way to plot multiple points on a single plot. Set
up the axes using the first point (or a junk point with type="n"), then
use points(x,y). You should almost never use par(new = TRUE).
Duncan Murdoch
>
> I must specify the input variable 'type', even though it defaults to "p",
> because the previous call to plot() was used to plot lines, and so type is
> set to "l".
> However, it is not clear to me why I must specify 'log'. It should still be
> equal to "" since it was not changed in any previous call to plot(), but if
> I do not specify it as above I get (4 of) the following message:
>
> Warning messages:
> 1: In plot.window(...) :
> nonfinite axis limits [GScale(-inf,0,1, .); log=1
>
> I would like to know the reason for this. Also, if my variables are named
> anything other than 'x' and 'y', the x and y axes are not labeled according
> to the xlab and ylab values I set in my call to plot. Why is this?
>
> Thank you very much.
More information about the R-help
mailing list