title: how to add layers in ggplot using a for-loop
body: <p>I would like to plot each column of a dataframe to a separate layer in ggplot2.
  Building the plot layer by layer works well:</p>
  
  <pre><code>df&lt;-data.frame(x1=c(1:5),y1=c(2.0,5.4,7.1,4.6,5.0),y2=c(0.4,9.4,2.9,5.4,1.1),y3=c(2.4,6.6,8.1,5.6,6.3))
  
  ggplot(data=df,aes(df[,1]))+geom_line(aes(y=df[,2]))+geom_line(aes(y=df[,3]))
  </code></pre>
  
  <p>Is there a way to plot all available columns at ones by using a single function?</p>
  
  <p>I tried to do it this way but it does not work:</p>
  
  <pre><code>    plotAllLayers&lt;-function(df){
      p&lt;-ggplot(data=df,aes(df[,1]))
      for(i in seq(2:ncol(df))){ 
          p&lt;-p+geom_line(aes(y=df[,i]))
          }
          return(p)
      }
  
  plotAllLayers(df)
  </code></pre>