美文网首页
【转】R画图的时候出现“null device 1”

【转】R画图的时候出现“null device 1”

作者: 白菜代码小推车 | 来源:发表于2019-06-27 10:12 被阅读0次

R画图的时候出现null device

问题

# Create data for the graph.
x <- c(21, 62, 10, 53)
labels <- c("London", "New York", "Singapore", "Mumbai")

# Give the chart file a name.
png(file = "city_title_colours.jpg")

# Plot the chart with title and rainbow color pallet.
pie(x, labels, main = "City pie chart", col = rainbow(length(x)))

# Save the file.
dev.off()

在运行上面R代码画饼图的时候会在命令输出窗口里面显示:

null device
                1

虽然图片是输出了,但是这个报错不知道是什么问题导致的。

解决办法

把之前的dev.off()改为下面这句话

while (!is.null(dev.list()))  dev.off()

这句话判断了当前图片输出设备是否有可用的,如果没有那也就不执行dev.off()这句话了,因为在之前到这句代码的时候已经输出了图片了,这里就不需要这句话了。

方法来源

参考

相关文章

网友评论

      本文标题:【转】R画图的时候出现“null device 1”

      本文链接:https://www.haomeiwen.com/subject/ofrlcctx.html