“jpeg” R中的函数不保存当前设备

发布于 2024-11-30 17:30:58 字数 438 浏览 1 评论 0原文

我正在尝试使用 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┈┾☆殇 2024-12-07 17:30:58

jpegX11 在某种意义上是竞争设备。您一次只能输出一件事。因此,当您在 jpeg 之后调用 X11 时,您就是在告诉 R 将所有输出发送到 X11 设备。取出 X11 并将高度和宽度参数直接传递给 jpeg

jpeg and X11 are in some sense competing devices. You can only output to one thing at a time. So when you call X11 after jpeg, you are telling R to send all output to the X11 device. Take out X11 and pass your height and width arguments directly to jpeg.

甜尕妞 2024-12-07 17:30:58

我不确定调用X11会产生什么效果。您可以直接设置宽度和高度:

jpeg('filename', width=20, height=30, units='cm', res=100)

I'm not sure what the effect of calling X11 will be. You could set the width and height directly:

jpeg('filename', width=20, height=30, units='cm', res=100)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文