(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Thu Sep 22 12:04:36 CEST 2005

```On 22-Sep-05 Ö£ä¿ wrote:
>                                                                 Sep,
> 22nd,2005
> Dear Authors,
> Thanks for reading this email. I'm a graduate student from China  (PRC)
> and learning the R at present.

Welcome!

I can't respond about the error messages you got when you were
installing R -- other people know more about what goes on during
the 'make' phase.

However:

> [...]
> The second bug occured when I was doing some ordinary statistical work.
> Suppose v1 is a numerical vector of length(v1)==20; further suppose
>> v1 <- c(1:20).
> When I type the command
>> lines(density(v1))
> or
>> rug(v1)
> simillar errors take place, and it prompts the following messages
> below: ( some key words of the promption are translated into English
. by myself)
> For the first command, it warns:
> "error occurs at: plot.xy(xy.coords(x, y), type = type, col = col, lty
> = lty, ...) :
>         'plot.new' hasn't been called yet"
>
> and for the second command, it warns:
> "error occurs at: axis(side, at = x, lab = FALSE, lwd = lwd, ...) :
>         'plot.new' hasn't been called yet"
> Besides: warnings:
> some values will be clipped in: rug(v1)"

Both of these represent the same type of error. The point is that
both the 'lines' and 'rug' commands *add* elements to an *existing*
plot, so neither will work unless there is already a plotted graph
in existence that they can add something to.

So (starting in a new R session):

v1<-c(1:20)
lines(v1)
# Error in plot.xy(xy.coords(x, y), type = type, col = col, lty = lty,
# ...) :
#         plot.new has not been called yet

However,

plot(v1)
lines(v1)

works by adding the lines to the existing plot of points.

Similarly (again starting from scratch):

v1<-c(1:20)
rug(v1)
#Error in axis(side, at = x, lab = FALSE, lwd = lwd, ...) :
#        plot.new has not been called yet
#some values will be clipped in: rug(v1)

However,

plot(v1)
rug(v1)

again works, adding the "rug" lines to the x-axis of the existing plot.

In each case the underlying reason can be seen if you read carefully
the opening lines of the "help" documentation for these functions,
which is shown if you enter

?lines

--> "Add Connected Line Segments to a Plot"

and

?rug

--> "Add a Rug to a Plot

Description:

Adds a _rug_ representation (1-d plot) of the data to the plot."

The critical word in these is "Add". And you can of course throw
them all in together with:

plot(v1)
lines(v1)
rug(v1)

As a person beginning to learn R, part of what one needs to learn
is that the documentation, available directly with "?" and also
via "help.search", usually contains the information you need
though you may need to interpret the wording of the documentation
carefully, even with the mind of a detective!

For example, the response to "?lines" that it will "Add Connected
Line Segments to a Plot" does not specify that there needs to be
an existing plot. Nor will you find such a statement anywehre in
the response to "?lines". Especially if one's native language is not
English (though I'm sure native speakers have been caught by this
as well), it might be natural to interpret this as allowing that
if the plot does not already exist then it will be created in such
a way as to accommodate the lines which will be added (to this
imaginary "null" object").

The clue in this case is in the error message:

plot.new has not been called yet

which does indicate that something which needed to be done has not
been done. In conjunction with the "Add" word, this could give you
the idea that maybe you should "plot(v1)" first!

Good luck, and best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 22-Sep-05                                       Time: 11:04:30
------------------------------ XFMail ------------------------------

```