Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print R graphics to multiple pages of a PDF and multiple PDFs?

Tags:

plot

r

graphics

I know that

 pdf("myOut.pdf") 

will print to a PDF in R. What if I want to

  1. Make a loop that prints subsequent graphs on new pages of a PDF file (appending to the end)?

  2. Make a loop that prints subsequent graphs to new PDF files (one graph per file)?

like image 655
Dan Goldstein Avatar asked Sep 08 '09 18:09

Dan Goldstein


People also ask

How do I save multiple graphs as PDF in R?

To save multiple plots to the same page in the PDF file, we use the par() function to create a grid and then add plots to the grid. In this way, all the plots are saved on the same page of the pdf file. We use the mfrow argument to the par() function to create the desired grid.

Can you print to PDF multiple PDFs at once?

Place all the PDFs that you want to print in a single folder and open it next to the printing queue's window. Select all the PDFs and drag them onto the printing queue's window. A window will pop up asking you to grant permission to print numerous files at once. Click on yes, and your printer will start printing.


2 Answers

Did you look at help(pdf) ?

Usage:

 pdf(file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"),      width, height, onefile, family, title, fonts, version,      paper, encoding, bg, fg, pointsize, pagecentre, colormodel,      useDingbats, useKerning) 

Arguments:

file: a character string giving the name of the file. For use with       'onefile=FALSE' give a C integer format such as       '"Rplot%03d.pdf"' (the default in that case). (See       'postscript' for further details.) 

For 1), you keep onefile at the default value of TRUE. Several plots go into the same file.

For 2), you set onefile to FALSE and choose a filename with the C integer format and R will create a set of files.

like image 173
Dirk Eddelbuettel Avatar answered Sep 22 '22 19:09

Dirk Eddelbuettel


Not sure I understand.

Appending to same file (one plot per page):

pdf("myOut.pdf") for (i in 1:10){   plot(...) } dev.off() 

New file for each loop:

for (i in 1:10){   pdf(paste("myOut",i,".pdf",sep=""))   plot(...)   dev.off() } 
like image 26
Mark Avatar answered Sep 22 '22 19:09

Mark