[R] persp plot + plotting grid lines

Kingsford Jones kingsfordjones at gmail.com
Sun Mar 15 15:07:46 CET 2009


Building on Duncan's code, here's an approximation to the Matlab
'peaks' plot referred to by Pedro:

peaks <-  function(x, y) { 3 * (1-x)^2 * exp(-(x^2)-(y+1)^2) -
  10 * (x/5-x^3-y^5) * exp(-x^2-y^2) - 1/3*exp(-(x+1)^2-y^2)}

x <- y <- seq(-3,3,.1)
z <- outer(x,y, peaks)
z2 <- 10 * round(c(z) + abs(min(z)) + 1)
jet.colors = colorRampPalette(c("#00007F", "blue", "#007FFF",
    "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
color <- jet.colors(160)[z2]

library(rgl)
persp3d(x,y,z, color=color, smooth=FALSE)
surface3d(x,y,z+0.001, front="lines", back="culled")



Kingsford Jones


On Sat, Mar 14, 2009 at 3:51 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 14/03/2009 12:02 PM, Pedro Mardones wrote:
>>
>> Dear all;
>> Does anyone know how to add grid lines to a persp plot? I've tried
>> using lines(trans3d..) but the lines of course are superimposed into
>> the actual 3d surface and what I need is something like the plot shown
>> in the following link:
>> http://thermal.gg.utah.edu/tutorials/matlab/matlab_tutorial.html
>> I'll appreciate any ideas
>
> I just posted a couple of demos of this using the rgl function persp3d, in
> the thread "Re: [R] can I draw 3D plot like this using R?".
>
> Duncan Murdoch
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list