title: Control layout when displaying a series of ggplot plots stored in a list
body: <p>I would like to control the layout when plotting a series of ggplots
  that I have stored in a list (generated automatically elsewhere).  </p>
  
  <p>I can plot series of plots as below.  </p>
  
  <pre><code>library(ggplot2)
  library(grid)
  library(gridExtra)
  p1 &lt;- ggplot(mtcars, (aes(x=mpg, fill=as.factor(1)))) + geom_density() +  
                        scale_fill_manual(values="red") 
  p2 &lt;- ggplot(mtcars, (aes(x=mpg, fill=as.factor(1)))) + geom_density() +  
                        scale_fill_manual(values="orange") 
  p3 &lt;- ggplot(mtcars, (aes(x=mpg, fill=as.factor(1)))) + geom_density() +  
                        scale_fill_manual(values="yellow") 
  p4 &lt;- ggplot(mtcars, (aes(x=mpg, fill=as.factor(1)))) + geom_density() +  
                        scale_fill_manual(values="green") 
  grid.arrange(p1, p2, p3, p4)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Qm63j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qm63j.png" alt="grid.arrange basic"></a></p>
  
  <p>I can then change their layout, as indicated <a href="https://stackoverflow.com/questions/30299529/ggplot2-define-plot-layout-with-grid-arrange-as-argument-of-do-call">here</a>.  </p>
  
  <pre><code>grid.arrange(p1, p2, p3, p4, layout_matrix=cbind(c(1,2), c(3,4)))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/JITQn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JITQn.png" alt="grid.arrange new layout"></a></p>
  
  <p>I can also plot a series of plots if they are stored in a list, as indicated <a href="https://stackoverflow.com/questions/10706753/how-do-i-arrange-a-variable-list-of-plots-using-grid-arrange">here</a>.  </p>
  
  <pre><code>myplotslist &lt;- list(p1, p2, p3, p4)
  do.call(grid.arrange, c(myplotslist, ncol=2))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/nk3JU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nk3JU.png" alt="enter image description here"></a></p>
  
  <p>But if I try to change the layout using layout_matrix, I get an error (and some warnings).</p>
  
  <pre><code>do.call(grid.arrange, c(myplotslist, ncol=2, layout_matrix=cbind(c(1,2), c(3,4))))
  
  Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1,  : 
    only 'grobs' allowed in "gList"
  In addition: Warning messages:
  1: In grob$wrapvp &lt;- vp : Coercing LHS to a list
  2: In grob$wrapvp &lt;- vp : Coercing LHS to a list
  3: In grob$wrapvp &lt;- vp : Coercing LHS to a list
  4: In grob$wrapvp &lt;- vp : Coercing LHS to a list
  </code></pre>
  
  <p>I have tried coercing the plot objects to grobs, but encounter the same error.</p>
  
  <pre><code>myplotslist2 &lt;- list(ggplotGrob(p1), ggplotGrob(p2), ggplotGrob(p3), ggplotGrob(p4))
  </code></pre>
  
  <p>I am using R 3.2.1, ggplot2 2.0.0, grid 3.2.1, and gridExtra 2.0.0, and would be extremely grateful for suggestions.  </p>