How to build a three-dimensional surface of a 3D matrix with R

I have a 3D matrix of floating point numbers, and I would like to create a smoothed three-dimensional surface of this matrix using R. Any suggestions are welcome. Thanks

Now I use scatterplot3d ... But this function did not create a smooth surface

x<-read.table("/Users/me/Desktop/data.txt") scatterplot3d(x$V1, x$V2, x$V3, highlight.3d = TRUE, angle = 30, col.axis = "blue", col.grid = "lightblue", cex.axis = 1.3, cex.lab = 1.1, pch = 20) 
+4
source share
3 answers

I think the mba.surf from the MBA package would be a good choice for smoothing, and as larrydag suggests, persp would be nice to mimic it. The code below is on the help page for the mba.surf function (replace LIDAR for your three-cylinder frame):

 data(LIDAR) mba.int <- mba.surf(LIDAR, 300, 300, extend=TRUE)$xyz.est # Two ways of imaging.... image(mba.int, xaxs="r", yaxs="r") persp(mba.int, theta = 135, phi = 30, col = "green3", scale = FALSE, ltheta = -120, shade = 0.75, expand = 10, border = NA, box = FALSE) 

enter image description here

+1
source

If you can create a 2D matrix (x, y) with a value that is the value of the z axis, you can use the following

 persp 

Here is an example from the graph gallery R. Example persp

+2
source
 require(misc3d) a <- 2/5 wsqr <- 1 - a^2 w <- sqrt(wsqr) denom <- function(a,w,u,v) a*((w*cosh(a*u))^2 + (a*sin(w*v))^2) fx <- function(u,v) -u + (2*wsqr*cosh(a*u)*sinh(a*u)/denom(a,w,u,v)) fy <- function(u,v) 2*w*cosh(a*u)*(-(w*cos(v)*cos(w*v)) - (sin(v)*sin(w*v)))/denom(a,w,u,v) fz = function(u,v) 2*w*cosh(a*u)*(-(w*sin(v)*cos(w*v)) + (cos(v)*sin(w*v)))/denom(a,w,u,v) parametric3d(fx = fx, fy = fy, fz = fz, umin = -17, umax = 17, vmin = -77, vmax = 77, n = 100, color = c("grey17","grey21","red4","darkred","red4","grey21","grey17"), engine = "rgl") 

enter image description here

+2
source

All Articles