Question

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

Était-ce utile?

La solution

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')
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top