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? Cheers Alex
On Dec 5, 2009, at 11:21 AM, 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? > > Cheers > > AlexIn the sequence you have above, each time you call plot(), you are erasing the prior plot. What you want is: jpeg(...) par(mfrow = (3, 1)) plot(...) plot(...) plot(...) dev.off() That will create a plot matrix of 3 rows and 1 column, which will be saved to the jpeg file. Each new plot will be below the prior one. A good way of going about this is to start by just plotting to the normal display device and then output to an external file. For the most part, the output should be similar, as long as you don't re-size the display device (eg. dragging a corner, etc.). With the code you have above, you would see right away that each new plot was clearing the prior one, thus knowing that this behavior was not unique to jpeg(). You can then tweak the plot as may be needed for the jpeg device. You can also use ?layout to play around with creating differing arrangements of plots within a single device instance. HTH, Marc Schwartz
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
On Dec 5, 2009, at 11:34 AM, Marc Schwartz wrote:> On Dec 5, 2009, at 11:21 AM, 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? >> >> Cheers >> >> Alex > > > In the sequence you have above, each time you call plot(), you are > erasing the prior plot. > > What you want is: > > jpeg(...) > > par(mfrow = (3, 1))Sorry, typo on that line. It should be: par(mfrow = c(3, 1)) Marc