[Solved] has not been called yet

Why does this happen?

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

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

Enquirer: optform


Solution #1:

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. (Could also be done by an extra when plotting to a file-graphics device. This may happen if you paste in a mult-line plotting command that has a dev,off() at the end of it but errors out at the opening of the external device but then has hte on a separate line so it 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 command. I just follow orders. When I get that error I issue 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.

Respondent: IRTFM

Solution #2:

In my case, I was trying to call plot(x, y) and lines(x, predict(yx.lm), col="red") in two separate chunks in Rmarkdown file. It worked without problems when running chunk by chunk, but the corresponding document wouldn’t knit. After I moved all plotting calls within one chunk, problem was resolved.

Respondent: Jelena?uklina

Solution #3:

As a newbie, I faced the same ‘problem’.

In newbie terms :
when you call plot(), the graph window gets the focus and you cannot enter further commands into R. That is when you conclude that you must close the graph window to return to R.
However, some commands, like identify(), act on open/active graph windows.
When identify() cannot find an open/active graph window, it gives this error message.

However, you can simply click on the R window without closing the graph window. Then you can type more commands at the R prompt, like identify() etc.

Respondent: Ronnie

Solution #4: error occurs when only part of the function is ran.

Please find the attachment for an example to correct error
With error….When abline is ran without plot() above
enter image description here
Error-free …When both plot and abline ran together
enter image description here

Respondent: Abhishek

Solution #5:

I had the same problem… my problem was that I was closing my quartz window after plot(x,y). Once I kept it open, the lines that previously resulted in errors just added things to my plot (like they were supposed to). Hopefully this might help some people who arrive at this page.

Respondent: Hank

Solution #6:

If someone is using print function (for example, with mtext), then firstly depict a null plot:


and then print with newpage = F

print(data, newpage = F)
Respondent: Alex Nevsky

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy