title: Overlaying an image plot on a perspective plot in R
body: <p>I apologize if this question has been answered before but I could not find an answer to this question through searching the site.  Basically what I would like to do is, in <code>R</code>, is to overlay an <code>image()</code> plot on top of a <code>persp()</code> plot so that basically what you would get is a 3D plot with a heat map on top of it corresponding to another function.  I have some sample code below of the functions that I am using:</p>
  
  <pre><code>x1 = seq(0,1,.01)
  x2 = seq(0,1,.01)
  
  f = function(x1,x2){
      ans = x1 + x2
      return(ans)
  }
  h = function(x1,x2){
      ans = 1.5-x1-2*x2-.5*sin(2*pi*(x1^2-2*x2))
      ans = sapply(ans,function(x){max(x,0)})
      return(ans)
  }
  
  z = outer(x1,x2,f)
  w = outer(x1,x2,h)
  
  persp(x1,x2,z)
  image(x1,x2,w)
  
  image(x1,x2,z,xlab=expression(x[1]),ylab=expression(x[2]))
  contour(x1,x2,w,add=T,nlevels=10)
  </code></pre>
  
  <p>So basically, I would like to generate this perspective plot below
  <img src="https://i.stack.imgur.com/B9ztV.png" alt="enter image description here">
  and then overlay this heatmap on top of the perspective plot surface
  <img src="https://i.stack.imgur.com/OrFxV.png" alt="enter image description here"></p>
  
  <p>To visualize what it should look like in 2D, I have been able to generate the following:
  <img src="https://i.stack.imgur.com/gk8uu.png" alt="enter image description here"></p>
  
  <p>I would much rather prefer to find an answer to this problem using the base packages in <code>R</code> but if I need to install a package to get what I need I am open to that as well.</p>