R图不显示图形窗口

Dan*_*tti 3 plot r

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

plot(rnorm(10))
obj = recordPlot()
replayPlot(obj)
Run Code Online (Sandbox Code Playgroud)

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

win.metafile()
plot(rnorm(10))
obj = recordPlot()
dev.off()
replayPlot(obj) # it shows a null plot
Run Code Online (Sandbox Code Playgroud)

好吧,可能是因为我在做obj = recordPlot()图时还没有准备好。

Mat*_*rde 5

来自?recordPlot

The displaylist can be turned on and off using dev.control. 
Initially recording is on for screen devices, and off for print devices.
Run Code Online (Sandbox Code Playgroud)

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

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