'jpeg' function in R not saving current device
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).B开发者_如何学Celow 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()
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
.
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)
精彩评论