I obtained a series of pictures with R and I want to save these pictures as pdf. However, I want to save these pictures in several separate pages instead of one page. What should I do?
After opening a PDF device, simply make serial calls to the plots. Each new plot will create a new page in the PDF file.
Example (not working by copy&paste, just for illustration):
pdf(...)
plot(y~x)
boxplot(df)
hist(y)
dev.off()
will create a pdf with 3 pages and a scatterplot on page 1, a boxplot on page 2 and a histogram on page 3.
EDIT:
The parameter "onefile" should be set to FALSE, what is the default. If this is not changed to TRUE and if the file is not a pipe, multiple pages will be created. Please have a look at the help page (?pdf):
onefile: logical: if true (the default) allow multiple figures in one file. If false, generate a file with name containing the page number for each page. Defaults to TRUE, and forced to true if file is a pipe.
After opening a PDF device, simply make serial calls to the plots. Each new plot will create a new page in the PDF file.
Example (not working by copy&paste, just for illustration):
pdf(...)
plot(y~x)
boxplot(df)
hist(y)
dev.off()
will create a pdf with 3 pages and a scatterplot on page 1, a boxplot on page 2 and a histogram on page 3.
EDIT:
The parameter "onefile" should be set to FALSE, what is the default. If this is not changed to TRUE and if the file is not a pipe, multiple pages will be created. Please have a look at the help page (?pdf):
onefile: logical: if true (the default) allow multiple figures in one file. If false, generate a file with name containing the page number for each page. Defaults to TRUE, and forced to true if file is a pipe.
@Jochen Wilhelm :great thanks for your detailed answer. a question added, if I want to save pictures which are generated in one operation(eg MA plot for 56 cel files),how can I save these pictures with several pages
Nan, this is written in the help. Set the argument "onefile=FALSE". You can use "%d" in the filename to indicate a position wher the plot number is placed. Another way is to create and close separate plots in a loop, for example
You can also consider working with R Markdown (integrated into Rstudio). Markdown files can be knit into pdf or html files (or even word files though I usually stick to the former two) and have the ability to retain useful information about your code along with your images if you so desire (or just the images). You can separate images using:
\pagebreak
between any two chunks of image code.
You can also write summaries and explanations of your graphs should you so desire and have them easily generated in paragraph form (with various formatting options). By far the code provided by Jochen Wilhelm above is more efficient, so if speed is the aim go with that. If you want a little added flair or the ability to add/control more features of the final document, then maybe check out R Markdown as an option.