[R] looping multipanel plots to different figures

efisio solazzo efisio.solazzo at jrc.ec.europa.eu
Thu Feb 19 11:16:42 CET 2015


Thanks Jim,
actually I need to keep open two devices at the same time, and within 
the loop access either of them in alternation. In MatLab there is the 
command Figure(#) which keeps track of the open devices and direct the 
output of the plot to whichever of them.

For example:
plot_filenames<-c("plot1.png","plot2.png","plot3.png")
for (i in 1:5) {
  png(plot_filenames[1])
  par(mfrow=c(1,2))
  hist(sample(i:10,30,TRUE)) #???
  png(plot_filenames[2]) #???
  par(mfrow=c(1,2))
  hist(sample(i+1:15,30,TRUE))
  dev.off() #???
}

Hope I've been clear.

Thanks, Efisio
===========================================



On 19/02/2015 10:36, Jim Lemon wrote:
> Hi efisio,
> I read this as wanting to start a new graphics device, then set some 
> plot parameters, display two plots and then close the graphics device 
> at each iteration of the loop. If so,
>
> plot_filenames<-c("plot1.png","plot2.png","plot3.png")
> for(plotfn in plot_filenames) {
>  png(plotfn)
>  par(mfrow=c(1,2))
>  hist(sample(1:5,30,TRUE))
>  hist(sample(1:5,30,TRUE))
>  dev.off()
> }
>
> Jim
>
>
> On Thu, Feb 19, 2015 at 7:25 PM, efisio solazzo 
> <efisio.solazzo at jrc.ec.europa.eu 
> <mailto:efisio.solazzo at jrc.ec.europa.eu>> wrote:
>
>     Dear,
>     cannot find  a way to direct multipanel plots to different figures
>     (files) while within a loop.
>
>     Say, the loop creates two plots each step: one plot should go to
>     figure 1 and the other to  figure 2.
>     Same for the next steps of the loop: the plots should go to figure
>     1 and  figure 2 in a multipanel fashion.
>
>     I am not sure at which point to open the files and set the
>     multipanel parameters...all I can get is two files with all plots
>     overlaid to the same position.
>
>     Thanks
>
>     ______________________________________________
>     R-help at r-project.org <mailto:R-help at r-project.org> mailing list --
>     To UNSUBSCRIBE and more, see
>     https://stat.ethz.ch/mailman/listinfo/r-help
>     PLEASE do read the posting guide
>     http://www.R-project.org/posting-guide.html
>     and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Efisio SOLAZZO, Ph.D.
European Commission, Joint Research Centre,
Institute for Environment and Sustainability,
TP123, Via E. Fermi, 2749 I-21027 Ispra (VA), Italy
Tel: +390332789944 Fax: +390332785837



	[[alternative HTML version deleted]]



More information about the R-help mailing list