title: R legend for color density scatterplot produced using smoothScatter
body: <p>I am producing a color density scatterplot in R using the <code>smoothScatter()</code> function.  </p>
  
  <p>Example:</p>
  
  <pre><code>## A largish data set
  n &lt;- 10000
  x1  &lt;- matrix(rnorm(n), ncol = 2)
  x2  &lt;- matrix(rnorm(n, mean = 3, sd = 1.5), ncol = 2)
  x   &lt;- rbind(x1, x2)
  oldpar &lt;- par(mfrow = c(2, 2))
  smoothScatter(x, nrpoints = 0)
  </code></pre>
  
  <p>Output:</p>
  
  <p><img src="https://i.stack.imgur.com/ZBpvV.png" alt="enter image description here"></p>
  
  <p>The issue I am having is that I am unsure how to add a legend/color scale that describes the relative difference in numeric terms between different shades.  For example, there is no way to tell whether the darkest blue in the figure above is 2 times, 10 times or 100 times as dense as the lightest blue without some sort of legend or color scale.  Is there any way in R to retrieve the requisite information to make such a scale, or anything built in that can produce a color scale of this nature automatically?</p>