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 --- ---
paste is the function you need. Bendix C. ---------------------- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 bxc at steno.dk www.biostat.ku.dk/~bxc ----------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > mike.campana at freesurf.ch > Sent: Monday, March 15, 2004 12:37 PM > To: r-help at stat.math.ethz.ch > Subject: [R] creating a ps. file > > > 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 > > --- > --- > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html >
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 > MikeYou 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
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...).Two comments: a) You might want to use postscript() directly with its argument onefile=FALSE. b) construct the filename with an index you are using in the loop (say "i"): dev.print(device=postscript, file = paste("c:/Rfigures/plot_", i, ".ps", sep = "")) Uwe Ligges> Could you give me an advice? Thanks a lot > > Best Regards > Mike > > --- > --- > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
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 > > >see ?postscript The following example saves two plots in a postscriptfile. R> postscript("test.ps") R> hist(1:100) R> hist(rnorm(100)) R> dev.off() null device 1 /mahmood arai>Best Regards >Mike > >--- >--- > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
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 > > >Hello - I've never done this in R (I'm a total 'R' newbie) but in C or Java, I've used the loop counter as a postfix (or prefix) for the file name. You could do it like this (non-R code): int max = 10; for(int i = 1; i < max; i++){ [ . . .] //code for plotting etc writer = PdfWriter.getInstance(document, new FileOutputStream(pdfTitle + "_" + i + ".pdf")); } This would give (assuming pdfTitle == "plot"): plot_1.pdf, plot_2.pdf and so and so forth Others may be able to provide pointers etc for writing loops in R. Hope this helps. -- chris ciotti (chris_ciotti at yahoo.com) PGP ID: 0xE94BB3B7
for (i in 1:n){ dev.print(postcript,file=paste("c:/Rfigures/plot_",i,".ps",sep="")) } Best! A.S. ---------------------------- Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: alessandro.semeria at cramont.it
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 lotHello, if you use: nruns <- 200 for(i in 1:nruns) { postscript(filename=paste("plot_", i+1000, ".ps", sep="")) # some plotting commands here # dev.off() } then you get your files in a sortable order without too much string manipulation. Of course, you can also use 10000 or whatever, if you want more figures. Thomas P.
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 lotHello, if you use: nruns <- 200 for(i in 1:nruns) { postscript(file=paste("plot_", i+1000, ".ps", sep="")) # some plotting commands here # dev.off() } then you get your files in a sortable order without too much string manipulation. Of course, you can also use 10000 or whatever, if you want more figures. Thomas P. Sorry: in the postscript() function the option is called "file" and not "filename" like in bmp() and png()
paste("c:/Rfigures/plot", i, ".ps", sep="")> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of > mike.campana at freesurf.ch > Sent: 15 March 2004 11:37 > To: r-help at stat.math.ethz.ch > Subject: [R] creating a ps. file > > > 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 > > --- > --- > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
Before the loop, open a postscript device with onefile=FALSE, and see the advice in the postscript help page for how to specify the file argument. Then each plot will produce a separate file. (Remember to do dev.off() after the loop.) On Mon, 15 Mar 2004 mike.campana at freesurf.ch wrote:> 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-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Mon, Mar 15, 2004 at 12:37:02PM +0100, mike.campana at freesurf.ch wrote:> 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 lotfor (i in 1:10) { x11(); plot(...) ... dev.copy2eps(file = paste("plot_", i, ".eps", sep = "")) } -- WBR, Timur