title: List of plots using lapply
body: <p>I have been using lapply and sapply as my go-to functions recently. So far so good, but why the following code does not work baffles me. </p>
  
  <pre><code>df&lt;-as.data.frame(matrix(rnorm(50),ncol=5))
  names(df)&lt;-c("x1","x2","x3","x4","x5")
  df1&lt;-seq_len(10)
  
  ll&lt;-lapply(seq(1,5), function(i) qplot(df1,df[,i]))
  </code></pre>
  
  <p>I get the error: </p>
  
  <pre><code>Error in `[.data.frame`(df, , i) : undefined columns selected
  </code></pre>
  
  <p>Ok, apparently I made quite an unfortunate mistake in my reproducible code. It works now, but all the plots in the <code>ll</code> list are the same plot. When I run this:</p>
  
  <p><code>do.call(grid.arrange,ll)</code></p>
  
  <p>I get the following image:</p>
  
  <p><img src="https://i.stack.imgur.com/7qy42.png" alt="Grid"></p>
  
  <p>All the plots are the same! This is also the output I get when I run this through my data.</p>