“jpeg” R中的函数不保存当前设备
我正在尝试使用 R 中的 jpeg 函数自动保存图形。如果我只使用默认图形设备并且不尝试更改它,该功能将完美运行。但是,当我尝试通过“X11”功能更改设备时,它不起作用(我认为它正在记录空设备而不是 X11 设备)。下面是一些您可以自行运行的代码。任何帮助将不胜感激!
x<-rnorm(10, 3, 4)
y<-rnorm(10, 68, 2)
jpeg(file="YOUR FILE PATH", quality=100)
X11(width=20, height=15)
par(mfrow=c(2,2))
plot(x,y, main="1")
plot(x,y,main="2")
plot(x,y, main="3")
plot(x,y,main="4")
dev.off()
I am trying to use the jpeg function in R to save graphics automatically. The function works perfectly if I just use the default graphics device and do not try to alter it. But when I try and alter the device by the 'X11' function it does not work (I think it is recording the null device and not the X11 device).Below is some code you can run your self. Any help would be greatly appreciated!
x<-rnorm(10, 3, 4)
y<-rnorm(10, 68, 2)
jpeg(file="YOUR FILE PATH", quality=100)
X11(width=20, height=15)
par(mfrow=c(2,2))
plot(x,y, main="1")
plot(x,y,main="2")
plot(x,y, main="3")
plot(x,y,main="4")
dev.off()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jpeg
和X11
在某种意义上是竞争设备。您一次只能输出一件事。因此,当您在jpeg
之后调用X11
时,您就是在告诉 R 将所有输出发送到 X11 设备。取出X11
并将高度和宽度参数直接传递给jpeg
。jpeg
andX11
are in some sense competing devices. You can only output to one thing at a time. So when you callX11
afterjpeg
, you are telling R to send all output to the X11 device. Take outX11
and pass your height and width arguments directly tojpeg
.我不确定调用
X11
会产生什么效果。您可以直接设置宽度和高度:I'm not sure what the effect of calling
X11
will be. You could set the width and height directly: