title: Print multiple plots on multiple pages in pdf
body: <p>I have a lot of plots of mass spec data that I want to spread out reasonably over several pages in a pdf. The idea is, that the plots are aligned vertically for easy comparison. That's why I need them to have a certain readable dimension, and I want each set of plots to go together on one page, the next set on the next page and so on. 
  So far, I managed to get either: well dimensioned plots on 1 page per file for multiple files; or: poorly dimensioned plots on several pages in one pdf. I'd like to have well dimensioned plots on several pages in one pdf. </p>
  
  <p>My data is in <code>COMBO</code></p>
  
  <p>Here is my code for solution (1):</p>
  
  <pre><code>totalrows &lt;- nrow(COMBO)
  pagesneeded &lt;- ceiling(totalrows/9)
  
  for(i in 1:pagesneeded){
  combolongrow &lt;- melt(COMBO, id.vars = "UnID")
  pl&lt;- 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)
  }
  </code></pre>
  
  <p>This creates a nicely spaced A4 pdf for each set of plots for a total of 8 pdf files in my case.</p>
  
  <p>Output: all spacing is nice, but every page is a separate file
  <img src="https://i.stack.imgur.com/KFT0d.jpg" alt="All spacing is nice, but every page is a separate file."></p>
  
  <p>Example (2):</p>
  
  <pre><code>totalrows &lt;- nrow(COMBO)
  pagesneeded &lt;- ceiling(totalrows/9)
  
  pdf("Plots.pdf", paper = "a4")
  for(i in 1:pagesneeded){
  combolongrow &lt;- melt(COMBO, id.vars = "UnID")
  pl&lt;- 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()
  </code></pre>
  
  <p>This creates one file (yay), but the plots are sized to the default graphics device size, which is the wrong aspect ratio and leaves large margins on all four sides of my plots and makes the data unreadable. </p>
  
  <p>Output: Spacing is bad, but all pages are automatically put together in one document.
  <img src="https://i.stack.imgur.com/cr4vD.jpg" alt="Spacing is bad, but all pages are automatically put together in one document."></p>
  
  <p>What can I do to get all plots through <code>ggsave</code> into one single file? Or how can I change the dimensions of my plots so that <code>pdf()</code> picks them up in the right size? </p>
  
  <p>Thanks for your help!</p>