我需要将绘图对象存储在变量中。我知道我可以做到:
plot(rnorm(10))
obj = recordPlot()
replayPlot(obj)
但是我不想显示图形窗口。因此,我正在尝试执行此操作,但直到现在都没有成功。
win.metafile()
plot(rnorm(10))
obj = recordPlot()
dev.off()
replayPlot(obj) # it shows a null plot
好吧,可能是因为我在做obj = recordPlot()图时还没有准备好。
来自?recordPlot:
The displaylist can be turned on and off using dev.control. 
Initially recording is on for screen devices, and off for print devices.
因此,如果要记录写入文件的绘图,则需要打开显示列表:
win.metafile()
dev.control('enable') # enable display list
plot(rnorm(10))
obj = recordPlot()
dev.off()
replayPlot(obj)