title: How to use ggplot to plot a list of dataframes and save them in a pdf file
body: <p>I have a data frame with this structure</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>date</th>
  <th>Campaign_name</th>
  <th>reach</th>
  <th>impressions</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>06/06/2021</td>
  <td>generic</td>
  <td>1423412</td>
  <td>32423</td>
  </tr>
  <tr>
  <td>06/06/2021</td>
  <td>remarketing</td>
  <td>232</td>
  <td>234</td>
  </tr>
  <tr>
  <td>06/06/2021</td>
  <td>generic</td>
  <td>213213</td>
  <td>23423</td>
  </tr>
  <tr>
  <td>06/06/2021</td>
  <td>remarketing</td>
  <td>123213</td>
  <td>23423</td>
  </tr>
  <tr>
  <td>06/06/2021</td>
  <td>generic</td>
  <td>214332</td>
  <td>23423</td>
  </tr>
  <tr>
  <td>06/06/2021</td>
  <td>remarketing</td>
  <td>32423</td>
  <td>23423</td>
  </tr>
  <tr>
  <td>06/06/2021</td>
  <td>generic</td>
  <td>234</td>
  <td>213213</td>
  </tr>
  <tr>
  <td>07/06/2021</td>
  <td>remarketing</td>
  <td>234234</td>
  <td>213123</td>
  </tr>
  <tr>
  <td>07/06/2021</td>
  <td>generic</td>
  <td>234234</td>
  <td>5465</td>
  </tr>
  <tr>
  <td>07/06/2021</td>
  <td>remarketing</td>
  <td>234234</td>
  <td>21321</td>
  </tr>
  <tr>
  <td>07/06/2021</td>
  <td>remarketing</td>
  <td>234234</td>
  <td>786786</td>
  </tr>
  <tr>
  <td>07/06/2021</td>
  <td>remarketing</td>
  <td>2342342</td>
  <td>785785</td>
  </tr>
  <tr>
  <td>07/06/2021</td>
  <td>acquisition</td>
  <td>543454345</td>
  <td>786774</td>
  </tr>
  <tr>
  <td>07/06/2021</td>
  <td>acquisition</td>
  <td>435345</td>
  <td>758785</td>
  </tr>
  <tr>
  <td>07/06/2021</td>
  <td>generic</td>
  <td>2344234</td>
  <td>7557</td>
  </tr>
  <tr>
  <td>08/06/2021</td>
  <td>remarketing</td>
  <td>213123</td>
  <td>7857</td>
  </tr>
  <tr>
  <td>08/06/2021</td>
  <td>remarketing</td>
  <td>234234</td>
  <td>7857</td>
  </tr>
  <tr>
  <td>08/06/2021</td>
  <td>generic</td>
  <td>234324</td>
  <td>757</td>
  </tr>
  <tr>
  <td>08/06/2021</td>
  <td>remarketing</td>
  <td>545345345345</td>
  <td>7857</td>
  </tr>
  <tr>
  <td>08/06/2021</td>
  <td>generic</td>
  <td>3423</td>
  <td>78578</td>
  </tr>
  <tr>
  <td>08/06/2021</td>
  <td>acquisition</td>
  <td>32423</td>
  <td>7578</td>
  </tr>
  <tr>
  <td>08/06/2021</td>
  <td>acquisition</td>
  <td>2343</td>
  <td>7587</td>
  </tr>
  <tr>
  <td>09/06/2021</td>
  <td>acquisition</td>
  <td>23423</td>
  <td>7578578</td>
  </tr>
  <tr>
  <td>09/06/2021</td>
  <td>acquisition</td>
  <td>2212</td>
  <td>785787878</td>
  </tr>
  <tr>
  <td>09/06/2021</td>
  <td>acquisition</td>
  <td>23234</td>
  <td>785757</td>
  </tr>
  <tr>
  <td>09/06/2021</td>
  <td>remarketing</td>
  <td>2342</td>
  <td>7575757</td>
  </tr>
  <tr>
  <td>09/06/2021</td>
  <td>remarketing</td>
  <td>23423</td>
  <td>578575857</td>
  </tr>
  <tr>
  <td>09/06/2021</td>
  <td>generic</td>
  <td>23423</td>
  <td>785757</td>
  </tr>
  <tr>
  <td>09/06/2021</td>
  <td>acquisition</td>
  <td>23432</td>
  <td>78575</td>
  </tr>
  <tr>
  <td>09/06/2021</td>
  <td>generic</td>
  <td>234</td>
  <td>7857757</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I need to make multiple plots for every campaign_name, for example:</p>
  <p>a plot a time series for the <em>generic</em> campaign name with <em>reach</em> and <em>impression</em> on the y axis</p>
  <p>and save it to a pdf</p>
  <p>I need to repeat this task for every type of campaign inside the campaign name column</p>
  <p>I have tried this</p>
  <pre><code>list_of_campaigns &lt;- unique(facebook_raw_daily$`Campaign name`)
  
  facebook_split &lt;- split(facebook_raw_daily, facebook_raw_daily$`Campaign name`)
  
  
  
  p &lt;- lapply(facebook_split, function(d)  ggplot(
    data = d,
    aes(
      x = &quot;date&quot;,
      y = &quot;reach&quot;,
      group = &quot;Campaign_name&quot;,
      colour = &quot;Campaign_name&quot;
    )
  ) + geom_line() )
  
  pdf(&quot;myplots2.pdf&quot;)
  do.call(&quot;grid.arrange&quot;, p)
  dev.off()
  </code></pre>
  <p>it generates a pdf file with multiple plots but they are blank and all inside one page which is not feasible, I would like to have a plot per page</p>
  <p>Any suggestion?</p>