title: Apply column names to legend in a function
body: <p>I'm writing a function that takes two variables -- ideally columns from the same data frame -- and plots them.  The plot will also include a legend using the names from the columns, and that's where I'm running into difficulty.</p>
  
  <p>The code below is as close to the desired outcome as I can get.  I'm only interested in using base R.</p>
  
  <pre><code>plotpairs &lt;- function(x,y){
    plot(x, type = "l", col = "red")
    lines(y, type = "l", col = "blue")
    legend(0,ylim_max, legend = paste0(x, y), lwd = c(5,5), col = c("red", "blue"), bty = "n")
  }
  
  plotpairs(df$F3, df$F4)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RdJCj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RdJCj.jpg" alt="enter image description here"></a></p>