Re: multiple plots per page, multiple pages

"Viechtbauer, Wolfgang \(NP\) via R-help" <[email protected]> Tue, 28 Apr 2026 09:32:08 +0000
Newsgroups gmane.comp.lang.r.general
Message-ID <PA4PR08MB7435DD86E9E896E593CF0A658B372@PA4PR08MB7435.eurprd08.prod.outlook.com>
Whoa - never realized that png() (and some other devices) have that feature. After using R for more than 25 years, it still blows my mind that I keep finding such gems in base R. Of course, when you look at help(png), it explains it right there for the filename argument (ducks in shame).

Best,
Wolfgang

> -----Original Message-----
> From: R-help <[email protected]> On Behalf Of Duncan Murdoch
> Sent: Tuesday, April 28, 2026 10:49
> To: Stefano Sofia <[email protected]>; [email protected]
> Subject: Re: [R] multiple plots per page, multiple pages
> 
> On 2026-04-28 4:11 a.m., Stefano Sofia via R-help wrote:
> > Deer R-list users,
> >
> > I need to create multiple plots per page, without using ggplot.
> >
> > Let's say that I want two plots per page, 3 pages.
> >
> > png(file="test.png", units="cm", res=200, width=19, height=24)
> >
> > par(mfrow=c(2,1))
> >
> > for(ii in 1:3){
> >
> > plot(ii,ii)
> >
> > hist(rnorm(10))
> >
> > }
> >
> > dev.off()
> >
> > overwrites the first two pages and creates only the third one.
> >
> > pdf(file="test.pdf")
> >
> > ...
> >
> > works fine, but I would like to stick to the png command. Is there a way to do
> it?
> 
> You can't have multiple pages in a single .png file, but R will create
> multiple .png files if you use a filename like "test%03d.png" (where the
> "%03d" suffix is a C-style format spec).
> 
> Duncan Murdoch
> >
> > Thank you for your help
> >
> > Stefano Sofia
> >
> >           (oo)
> > --oOO--( )--OOo--------------------------------------
> > Stefano Sofia MSc, PhD
> > Civil Protection Department - Marche Region - Italy
> > Meteo Section
> > Snow Section
> > Via Colle Ameno 5
> > 60126 Torrette di Ancona, Ancona (AN)
> > Uff: +39 071 806 7743
> > E-mail: [email protected]
> > ---Oo---------oO----------------------------------------