Re: [R] Multiple plot jpeg file

From: Marc Schwartz <>
Date: Tue, 19 Jun 2007 14:53:56 -0500

On Tue, 2007-06-19 at 15:39 -0400, Bill Hunsicker wrote:
> R-Help,
> I am executing a R script and would like to put multiple plots into a
> single file. For some reason the contents of plotfile.jpg always seem to
> contain the last plot and not all plots.
> If I do same thing with pdf, a multiple plot file is created.
> Can you help me?
> Regards,
> Bill

There is no notion of a 'page' in bitmapped devices as there is with PDF or PS devices. Thus, each time you call plot(...) with a bitmapped device, the previous output is lost.

If you want multiple plots in a bitmapped device, you would need to use layout() or par(mfrow/mfcol) to define multiple plot regions within the overall bitmapped output.

For example:

jpeg("test.jpg", 400, 400)

# Set for 2 rows, 1 col
par(mfrow = c(2, 1))

# Set the margins to make room
par(mar = c(1, 4, 4, 2))

# Draw a barplot

# Set the margins to make room
par(mar = c(5, 4, 1, 2))

# Do a scatterplot

# Close the device

Adjust other pars as required.

See ?par and ?layout

HTH, Marc Schwartz mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 19 Jun 2007 - 20:00:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Jun 2007 - 21:32:37 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.