Skip to content
Prev 173456 / 398506 Next

can I draw 3D plot like this using R?

On 11/03/2009 11:35 PM, Oliver wrote:
It is a little tricky to draw both lines and solid colours on a surface 
in rgl, because one will hide the other:  there's no way to turn off the 
hidden object removal in rgl.

The easiest way to do it would be to draw the grid slightly above the 
surface.  For example,

x <- seq(-2, 2, len=17)
y <- seq(-2, 2, len=17)
z <- outer(x,y, function(x,y) exp(-y^2)*sin(1.5*x))
color <- rainbow(41)[1+round(10*outer(x,y, function(x,y) x^2 + y^2))]

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

(Fiddle with the 0.001 value if the grid disappears behind the surface, 
or floats too high above it.)

Another way would be to draw the grid (and maybe the colour) as a texture.

Duncan Murdoch