title: Formatting of persp3d plot
body: <p>I have the following 3d plot:</p>
  
  <p><img src="https://i.stack.imgur.com/04AOC.png" alt="ro"></p>
  
  <p>With my <a href="http://uploadeasy.net/upload/15k2d.rar" rel="nofollow noreferrer">data</a> I created it with the following code:</p>
  
  <pre><code>library(rugarch)
  library(rgl)
  library(fGarch)
  
  fd &lt;- as.data.frame(modelfit, which = 'density')
  color &lt;- rgb(85, 141, 85, maxColorValue=255)
  
  x &lt;- seq(-0.2, 0.2, length=100)
  y &lt;-c(1:2318)
  
  f &lt;- function(s, t) {
   dged(s,mean=fd[t,'Mu'],sd=fd[t,'Sigma'],nu=fd[t,'Shape'])
  
  }
  
  z &lt;- outer(x, y, f)
  persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color,
        ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)
  </code></pre>
  
  <p>How can I get a coloring depending on the z values? I looked at different solutions, e.g. this <a href="https://stackoverflow.com/questions/10357002/create-3d-plot-colored-according-to-the-z-axis">one</a>, but I could not create the coloring depending on the z values in this case.
  The solution according to <a href="https://stackoverflow.com/questions/10357002/create-3d-plot-colored-according-to-the-z-axis?rq=1">this thread</a> would be the following:</p>
  
  <pre><code>nrz &lt;- nrow(z)
  ncz &lt;- ncol(z)
  jet.colors &lt;- colorRampPalette( c("#ffcccc", "#cc0000") ) 
  # Generate the desired number of colors from this palette
  nbcol &lt;- 100
  color &lt;- jet.colors(nbcol)
  
  # Compute the z-value at the facet centres
  zfacet &lt;- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
  # Recode facet z-values into color indices
  facetcol &lt;- cut(zfacet, nbcol)
  
    persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[facetcol],
            ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)
  </code></pre>
  
  <p>But this does not give a good result, since it does not color the plot appropriate. I want  to have the spikes of my surface to be e.g. in red and the low values to be e.g. in blue with a nice smooth transition, but this kind of colors the slices, so depending on the time? So extreme large spikes should be colored at their spikes in red and values at the bottom e.g. in green. How can I get this?</p>
  
  <p>Edit: I found a solution to my previous question about the date on the axis, the only problem left, is an appropriate coloring dependent on the z values.</p>