1
votes

I created a 3D plot with the RGL library for R. The result is this image:

[image with a continuous surface]

But I need a reticular surface, like this:

[image with reticular surface]

...preserving the ability of RGL to interactively rotate the plot. How can I do it?

My code is this:

library(rgl)

bg3d("white")

persp3d( x, y, hdif, col = "lightblue", xlab = "Years from diagnosis", ylab = "Age at diagnosis", zlab = "Hazard difference", zlim= c(-10, 80), resfac = c(.15, 1), nticks = 70)

grid3d(c("x", "y+", "z"))

1

1 Answers

1
votes

I think you'll get something like that if you plot the surface several times with different options.

The first time should be

persp3d( x, y, hdif, col = "white", xlab = "Years from diagnosis", 
         ylab = "Age at diagnosis", zlab = "Hazard difference", 
         zlim= c(-10, 80), lit = FALSE)

(I left out a couple of your parameters that should not be here: nticks and resfac.) This will get a solid surface, but it won't show up because it is pure white.

The second time should be

surface3d( x, y, hdif, col = "blue", front = "lines", back = "cull", lit = FALSE)

This will get the blue line mesh. Finally you can plot

surface3d( x, y, hdif, col = "red", front = "cull", back = "lines", lit = FALSE)

for the red lines on the back: but due to rounding error, it might leak through in some places, so I'd use the same colour for front and back, i.e.

surface3d( x, y, hdif, col = "blue", front = "cull", back = "lines", lit = FALSE)

There are likely to be a few artifacts due to rounding; you could add depth_test = "lequal" to the mesh calls and it might help, or shift the front up a tiny bit and the back down a tiny bit by modifying hdif.