[R] three plots as one JEPG?

Duncan Murdoch murdoch at stats.uwo.ca
Sat Dec 5 18:35:59 CET 2009


On 05/12/2009 12:21 PM, Walther, Alexander wrote:
> Dear List,
> 
> 
> i have a question concerning these device-related function (i.e.
> pdf(),jpeg(), etc.). Currently, I plot three graphs, one below the other
> into a /single/ window by using par(). I would like to save this figure
> now as JPEG or PNG. By now, code looks as follows:
> 
> 
> jepg(...)
> 
> par(...)
> plot(...)
> 
> par(...)
> plot(...)
> 
> par(...)
> plot(...)
> 
> dev.off()
> 
> 
> Unfortunaltely, I just get the last plot saved, the rest is dismissed.
> Does anyone have a solution for this problem?

Sure, just do it like this:

jpeg(...)
par(mfrow=c(3,1))
plot(...)
plot(...)
plot(...)
dev.off()

There's also the layout() function, and more elaborate layout 
possibilities in the grid package.  But the basic idea is that you want 
the code to generate just one image on screen if you use a screen device 
rather than jpeg(), then jpeg() will generate something very similar.

Duncan Murdoch




More information about the R-help mailing list