Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot.new has not been called yet

Tags:

plot

r

Why does this happen?

plot(x,y) yx.lm <- lm(y ~ x) lines(x, predict(yx.lm), col="red") 

Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet

like image 558
optform Avatar asked Aug 22 '11 22:08

optform


People also ask

How do you fix plot new has not been called yet?

We can fix this error easily by creating a plot before using the lines() function: Example: Here, in this example, we are fixing the above error by simply calling the plot function before the lines() function to get the idea of the points given.

What does plot new has not been called yet mean?

This error occurs when you attempt to perform some action that requires a plot to already exist in R, yet a plot does not exist.

How do I add a title to a plot in R?

Add Titles to a Graph in R Programming – title() Function title() function in R Language is used to add main title and axis title to a graph. This function can also be used to modify the existing titles. Syntax: title(main = NULL, sub = NULL, xlab = NULL, ylab = NULL, …)

What is the function of Abline H 5?

The h= and v= forms draw horizontal and vertical lines at the specified coordinates. The coef form specifies the line by a vector containing the slope and intercept. reg is a regression object with a coef method.


1 Answers

Some action, very possibly not represented in the visible code, has closed the interactive screen device. It could be done either by a "click" on a close-button, or it could also be done by an extra dev.off() when plotting to a file-graphics device. (The second possibility might happen if you paste in a multi-line plotting command that has a dev.off() at the end of it, but had errored out at the opening of the external device. So the dangling dev.off() on a separate line accidentally closes the interactive device).

Some (most?) R implementations will start up a screen graphics device open automatically, but if you close it down, you then need to re-initialize it. On Windows that might be window(); on a Mac, quartz(); and on a Linux box, x11(). You also may need to issue a plot.new() command. I just follow orders. When I get that error I issue plot.new() and if I don't see a plot window, I issue quartz() as well. I then start over from the beginning with a new plot(., ., ...) command and any further additions to that plot screen image.

like image 162
IRTFM Avatar answered Oct 02 '22 10:10

IRTFM