title: Gradient legend in base
body: <p>Earlier I asked about creating a gradient of n values in base graphics (<a href="https://stackoverflow.com/questions/13353213/gradient-of-n-colors-ranging-from-color-1-and-color-2#comment18225943_13353213">LINK</a>).  Now I'd like to create a gradient legend that goes with it.  My ideal would be something like <code>ggplot2</code>'s gradient legends:</p>
  
  <p><img src="https://i.stack.imgur.com/tsP1X.png" alt="enter image description here"></p>
  
  <p>Here's some code similar to what I'm working with:</p>
  
  <pre><code>colfunc &lt;- colorRampPalette(c("red", "blue"))
  plot(1:20, 1:20, pch = 19, cex=2, col = colfunc(20))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/MSamK.png" alt="enter image description here"></p>