Printing multiple graphs on multiple pages in pdf

I have many stories with data on mass specifications that I want to spread out over several pages in pdf format. The idea is that the graphs for alignment are vertically aligned. Therefore, I need them to have a certain readable dimension, and I want each set of graphs to come together on one page, next on the next page, and so on. So far, I managed to get either: well-calculated graphs on 1 page per file for several files; or: low-dimensional graphics on several pages in one pdf. I would like to have well-calculated graphs on several pages in one PDF file.

My data is in COMBO

Here is my code for solving (1):

 totalrows <- nrow(COMBO) pagesneeded <- ceiling(totalrows/9) for(i in 1:pagesneeded){ combolongrow <- melt(COMBO, id.vars = "UnID") pl<- ggplot(combolongrow, aes(x=variable , y=value, group=UnID)) + geom_line() + theme(strip.text.y = element_text(size=6)) + xlab("Fraction") + ylab("iBAQ") + facet_wrap_paginate(~UnID, ncol = 1, nrow = 9, page = i, strip.position="top", scales="free_y") ggsave(paste("plot-", i, ".pdf", sep=""), width=21, height=29, units ="cm", dpi = 300) } 

This creates a convenient A4 PDF format for each chart set for 8 PDF files in my case.

Output: all intervals are good, but each page is a separate file All spacing is nice, but every page is a separate file.

Example (2):

 totalrows <- nrow(COMBO) pagesneeded <- ceiling(totalrows/9) pdf("Plots.pdf", paper = "a4") for(i in 1:pagesneeded){ combolongrow <- melt(COMBO, id.vars = "UnID") pl<- ggplot(combolongrow, aes(x=variable , y=value, group=UnID)) + geom_line() + theme(strip.text.y = element_text(size=6)) + xlab("Fraction") + ylab("iBAQ") + facet_wrap_paginate(~UnID, ncol = 1, nrow = 9, page = i, strip.position="top", scales="free_y") print(pl) } dev.off() 

This creates a single file (yay), but the graphs are sized to the default size of the graphics device, which is an incorrect aspect ratio and leaves large margins on all four sides of my graphs and makes the data unreadable.

Output: The interval is bad, but all pages are automatically folded into one document. Spacing is bad, but all pages are automatically put together in one document.

What can I do to get all graphs via ggsave into one file? Or how can I resize my stories so that pdf() takes them in the right size?

Thanks for your help!

+1
source share
1 answer

Try the following:

 pdf("Plots.pdf", paper = "a4") par.save <- par(mfrow = c(4, 1)) for(i in 1:20) { plot(1:10) } par(par.save) dev.off() 
0
source

All Articles