title: How to generate multiple ggplots using a for loop
body: <p>I was wondering if someone could help me get this code to return multiple graphs. I would like each graph to be labelled &quot;plot_i&quot; (plot_G1, plot_G2). I am at a loss as to how to get my function to return this. Any help would be appreciated!</p>
  <pre><code>library(lubridate)
  library(tidyverse)
  
  #Dummy Data Frame
  DateTime &lt;- c(&quot;1999/01/01 11:00&quot;,&quot;1999/01/02 11:00&quot;,&quot;1999/01/03 11:00&quot;,&quot;1999/01/01 11:00&quot;,&quot;1999/01/02 11:00&quot;,&quot;1999/01/03 11:00&quot;,&quot;1999/01/01 11:00&quot;,&quot;1999/01/02 11:00&quot;,&quot;1999/01/03 11:00&quot;)
  Step &lt;- c(&quot;Condition1&quot;,&quot;Condition1&quot;,&quot;Condition1&quot;,&quot;Condition2&quot;,&quot;Condition2&quot;,&quot;Condition2&quot;,&quot;Condition3&quot;,&quot;Condition3&quot;,&quot;Condition3&quot;)
  G1 &lt;- runif(9)
  G2 &lt;- runif(9)
  G3 &lt;- runif(9)
  G4 &lt;- runif(9)
  test_df &lt;- data.frame(DateTime = DateTime, Step = Step, G1 = G1, G2 = G2, G3 = G3, G4 = G4)
  test_df$DateTime.lub &lt;- ymd_hm(test_df$DateTime)
  test_df
  
  #Want to create a function that will provide graphs for every G1, G2, G3 and G4 and return them! 
  list &lt;- colnames(test_df)
  list &lt;- list[-c(1,2,7)]
  list
  
  #test plot - works
  ggplot(data = test_df, aes(x= DateTime.lub, y = G1))+
                 geom_line(aes(size = Step))
  
  #Function does not return graph
  for (i in list){
      ggplot(data = test_df, aes(x= DateTime.lub, y = i))+
          geom_line(aes(colour = Step))
  }
  </code></pre>