title: Plot multiple ROC curves with ggplot2 in different layers
body: <p>I am trying to plot multiple ROC curves on a single plot with ggplot2. Here is how far I got:</p>
  
  <pre><code>ggroc2 &lt;- function(columns, data = mtcars, classification = "am",
                     interval = 0.2, breaks = seq(0, 1, interval)){
    require(pROC)
    require(ggplot2)
  
    #The frame for the plot
    g &lt;- ggplot() + geom_segment(aes(x = 0, y = 1, xend = 1,yend = 0)) +
      scale_x_reverse(name = "Specificity",limits = c(1,0), breaks = breaks, 
  expand = c(0.001,0.001)) + 
      scale_y_continuous(name = "Sensitivity", limits = c(0,1), breaks = 
  breaks, expand = c(0.001, 0.001)) +
      theme_classic() + coord_equal()
  
    #The loop to calculate ROC's and add them as new layers
    for(i in 1:length(columns)){
      croc &lt;- roc(data[,classification], data[,columns[i]]) 
      plotx &lt;- rev(croc$specificities)
      ploty &lt;- rev(croc$sensitivities)
      g &lt;- g + geom_step(aes(x=plotx, y=ploty))
    }
  
    g
  }
  
  
  
  #Sample graph
  ggroc2(c("mpg", "disp", "drat", "wt"))
  </code></pre>
  
  <p>The problem is that only the last parameter in the <code>columns</code> list gets plotted. I identified that the problem must be related to <code>aes()</code> and lazy evaluation after reading <a href="https://stackoverflow.com/questions/24617414/enriching-a-ggplot2-plot-with-multiple-geom-segment-in-a-loop">the answer to this question</a>. That example used <code>geom_segment()</code>, and the problem is solved after removing <code>aes()</code> altogether. It doesn't work for me, because I need to somehow map the data. When I remove <code>aes()</code> here, nothing gets plotted. How do I work around the lazy evaluation problem in <code>geom_</code>'s that depend on <code>aes()</code>?</p>