3
votes

I have a following data:

library(rgl)
x <- c(rep(1,6),
       rep(3,6),
       rep(6,6),
       rep(9,6),
       rep(12,6))
y <- c(1.35,1.39,1.48,1.29,1.35,1.32,
       NA,1.5,1.44,1.6,1.5,1.41,
       NA,NA,1.72,1.56,1.6,1.55,
       NA,NA,NA,1.95,1.9,1.75,
       NA,NA,NA,NA,2.05,1.95)
z <- rep(1:6,5)
open3d()
plot3d(x,y,z, type = 'n')
lines3d(x,y,z)

Which is plotting lines in 3d as I expect. But I cannot get it to plot a surface3d. As I already read some threads I might need to interpolate my data. RGL docs has not cover this subject well. I tried akima but it doesn't accept NA's. I would like to link lines to create a surface in linear way. I aware of the NA, so I expect that surface will be decreasing in the area for bigger x (more NA's). Do I need to perform interpolation? If yes, how to do that on my sample data? If no, how to achieve the surface3d on my sample data? Thanks

1
I don't know where your x, y and z data come from originally, bu there is surface3d in rgl. It requires y length == x rows * z cols however, which may not be possible with your data. But maybe you can reformat it. All surface plotting functions are going to require an xy grid with a z value for each xy value. See example(surface3d). - Bryan Hanson
Or, if you must connect the points you have as is, in a mesh fashion, you could construct all possible segments between your points and then draw them with segments3d. expand.grid might be helpful in this regard. Or try this SO post - Bryan Hanson
x is 'window width' used in rollapply function, y is the results of rollaplly, z is time index. - jangorecki
I've done something like this before with tripack, constructing the Delaunay triangulation/Voronoi diagram. At the moment I can't get it to work with these data points ... - Ben Bolker

1 Answers

1
votes

the solution comes to me from this thread: Making a wireframe plot from an x,y,z data.frame below code will work for the sample data provided above (just switch x->y,y->z,z->x)

zmat <- matrix(data = z, nrow = 6, ncol = 5, byrow = FALSE)
surface3d(x = 1:6, y = c(1,3,6,9,12), z = zmat, alpha = 0.4, colour = 'blue')