title: R: Adding Legends to Maps
body: <p>I am using the R programming language. I am trying to replicate the following stackoverflow post (creating geospatial heatmaps): <a href="https://stackoverflow.com/questions/44749346/r-heatmap-stat-density2d-ggmap-vs-addheatmap-shiny-leaflet">r heatmap - stat_density2d (ggmap) vs. addHeatmap (shiny leaflet)</a></p>
  <p>I simulated some geo-spatial data to match the format of the original data:</p>
  <pre><code>Lat = round(runif(5000,43,44), 4)
  Long = round(runif(5000,79,80), 4)
  a &lt;- rnorm(5000,100,10)
  
  map_data &lt;- data.frame(Lat, Long, a)
  map_data$Long = -1 * map_data$Long
  </code></pre>
  <p>Next, the following code is run to create the entire output:</p>
  <pre><code>#load libraries
      library(leaflet)
      library(leaflet.extras)
      
  #make heatmap for variable &quot;a&quot;
      leaflet(map_data) %&gt;%
        addTiles(group=&quot;OSM&quot;) %&gt;%
        addHeatmap(group=&quot;a&quot;, lng=~Long, lat=~Lat, max=.6, blur = 60)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/X9FrP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X9FrP.png" alt="enter image description here" /></a></p>
  <p>Is it possible to add a legend to this map that shows the &quot;intensity&quot; of the variable <code>map_data$a</code>?</p>
  <p>I looked at the documentation for this function : <a href="https://www.rdocumentation.org/packages/leaflet.extras/versions/1.0.0/topics/addHeatmap" rel="nofollow noreferrer">https://www.rdocumentation.org/packages/leaflet.extras/versions/1.0.0/topics/addHeatmap</a></p>
  <p>And there does not seem to be an option that allows you to add a legend.</p>
  <p>Thanks</p>