plot.new 还没有被调用 [英] plot.new has not been called yet

查看:175
本文介绍了plot.new 还没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会发生这种情况?

plot(x,y)yx.lm <- lm(y ~ x)行(x,预测(yx.lm),col =红色")

<块引用>

plot.xy(xy.coords(x, y), type = type, ...) 中的错误:plot.new 还没有被调用

解决方案

某些动作,很可能没有在可见代码中表现出来,关闭了交互式屏幕设备.它可以通过点击"或点击"来完成.在关闭按钮上,或者在绘图到文件图形设备时也可以通过额外的 dev.off() 来完成.(如果您粘贴多行绘图命令,该命令末尾带有 dev.off() ,但在打开外部设备时出错,则可能会发生第二种可能性.所以单独行上的悬空 dev.off() 意外关闭了交互式设备.

某些(大多数?)R 实现会启动一个自动打开的屏幕图形设备,但是如果您将其关闭,则需要重新初始化它.在 Windows 上可能是 window();在 Mac 上,quartz();在 Linux 机器上,x11().您可能还需要发出 plot.new() 命令.我只是听从命令.当我收到该错误时,我会发出 plot.new() 并且如果我没有看到绘图窗口,我也会发出 quartz() .然后我从头开始使用新的 plot(., ., ...) 命令和对该绘图屏幕图像的任何进一步添加.

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

解决方案

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.

这篇关于plot.new 还没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆