R图不显示图形窗口 [英] R plot without showing the graphic window

查看:595
本文介绍了R图不显示图形窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将绘图对象存储在变量中.我知道我可以做到:

I need to store a plot object in a variable. I know that I can do:

plot(rnorm(10))
obj = recordPlot()
replayPlot(obj)

但是我不想显示图形窗口.因此,我正在尝试执行此操作,但直到现在都没有成功.

But I don't want to show the graphic window. So I'm trying to do this, but with no success until now.

win.metafile()
plot(rnorm(10))
obj = recordPlot()
dev.off()
replayPlot(obj) # it shows a null plot

好吧,可能是因为当我执行obj = recordPlot()时,情节还没有准备好.

Well, probably because when I'm doing obj = recordPlot() the plot isn't ready yet.

推荐答案

来自?recordPlot:

The displaylist can be turned on and off using dev.control. 
Initially recording is on for screen devices, and off for print devices.

因此,如果要记录写入文件的图,则需要打开显示列表:

So you need to turn on the displaylist if you want to record a plot writing to file:

win.metafile()
dev.control('enable') # enable display list
plot(rnorm(10))
obj = recordPlot()
dev.off()
replayPlot(obj)

这篇关于R图不显示图形窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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