'dev.copy' 将当前设备的图形内容复制到指定的设备中。如果当前设备是:
windows() # or perhaps X11
plot(1:10)
dev.copy(device=pdf,file='hello.pdf')
dev.off()
dev.off()
通过这种方法,我们可以将相同的绘图复制到多个设备(格式)。
如果源设备是非 GUI 设备怎么办?我想以批处理模式复制多种格式的绘图,因此_不向用户显示 GUI 窗口。
但是:
png() # or other non-GUI devs
plot(1:10)
dev.copy(device=pdf,file='hello.pdf')
dev.off()
dev.off()
没用。事实上,该设备在关闭之前一直是空的,但关闭后,它就不再可用于复制。
有什么想法吗?
最佳答案
您需要调用 dev.control('enable')
。来自 ?dev.copy
:
dev.copy copies the graphics contents of the current device to the device specified...(If recording is off on the current device, there are no contents to copy: this will result in no plot or an empty plot.) ... The displaylist can be turned on and off using dev.control. Initially recording is on for screen devices, and off for print devices.
关于带有非 GUI 设备的 R dev.copy() 用于批处理图形脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24840979/