title: Changing title of plots in a loop with colnames() in R
body: <p>I am creating a for loop which creates a ggplot2 plot for each of the first six columns in a dataframe. Everything works except for the looping of the title names. I have been trying to use <code>title = colnames(df[,i])</code> and <code>title = paste0(colnames(df[,i])</code> to create the proper title but it simply ends up repeating the 2nd column name. The plots themselves produce the data correctly for each column, but the title is for some reason not looping. For the first plot it produces the correct title, but then for the second plot and beyond it just keeps on repeating the third column name, completely skipping over the second column name. I even tried creating a variable within the loop to store the respective title name to then use within the ggplot2 title labels: <code>changetitle &lt;- colnames(df[,i])</code> and then using <code>title = changetitle</code> but that also loops incorrectly. </p>
  
  <p>Here is an example of what I have so far:</p>
  
  <pre><code>plot_6 &lt;- list()
  
  for(i in df[1:6]){
     plot_6[i] &lt;- print(ggplot(df, aes(x = i, ...) ...) +
               ... +
               labs(title = colnames(df[,i]),
                    x = ...) +
               ...)
  }
  </code></pre>
  
  <p>Thank you very much.</p>