[R] creating a ps. file

Marc Schwartz MSchwartz at medanalytics.com
Mon Mar 15 15:07:00 CET 2004


On Mon, 2004-03-15 at 05:37, mike.campana at freesurf.ch wrote:
> Dear all
> 
> I wrote a routine. At the end of each cycle of the loop I would like to 
> save the result (plot) in a postcriptfile.
> Of course if I just use dev.print in the following way: 
> dev.print(device=postcript, 'c:/Rfigures/plot_1.ps")
> I overwrite my results with the second cycle of the loop. I suppose 
> there is a way to define the file name so that several plots are 
> created(plot_1,plot_2...).
> 
> Could you give me an advice? Thanks a lot
> 
> Best Regards 
> Mike


You can use paste() within a loop to construct the name of the resultant
ps files. An example:

number.graphics <- 5
for(i in 1:number.graphics)
  {
    postscript(file = paste("C:/Rfigures/plot_", i, ".ps", sep = ""))
    barplot(1:i)
    dev.off()
  }

The above will create 5 ps files called plot_1.ps through plot_5.ps in
the defined directory.

See ?paste for additional information.

HTH,

Marc Schwartz




More information about the R-help mailing list