title: heat map with image as background
body: <p>I am trying to make a heat map with R. I am trying with ggplot2.My actual dataframe is much larger but in here I only include a small part </p>
  
  <pre><code>x &lt;- c(502.9, 512.1, 716.6, 759.7, 776.1, 776.5, 736.1, 271.3, 304.7, 279.9, 263.8, 726.6, 767.6, 778.8, 779.2, 263.6, 291.8, 472.6, 499.9, 684.9) 
  y &lt;- c(374.6, 367.4, 378.1, 373.7, 381.4, 395.7, 412.1, 399.2, 364.6, 382.1, 409.1, 410.4, 411.1, 429.4, 477.4, 468.6, 406.5, 343.2, 356.9, 365.2)
  a &lt;- data.frame(x,y)
  ggplot(a, aes(x = x, y =y))  + stat_density2d(geom = "tile", aes(fill = ..density..), contour = FALSE) + scale_fill_gradient (low= "green", high="red") + geom_point()
  </code></pre>
  
  <p>I would like to obtain something similar to this image, the more red the area is, the more points there are in that area.</p>
  
  <p><a href="https://i.stack.imgur.com/cWLs8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cWLs8.jpg" alt="enter image description here"></a></p>
  
  <p>As you can see, when I try to make this, my background is green. How can I change my code to obtain a heatmap as the one showed in the image? How can I put an image as background?</p>
  
  <p>Thanks!</p>