I have the following data-set, and need to plot a surface based on this set of data (of 60 3D points). Here, X, Y is the horizontal plane coordinates, and Z is the vertical / height coordinate.
p = read.csv("points.csv")
PTS X Y Z
1 101 481897.9 5456408 94.18695
2 102 481888.8 5456417 94.30702
3 103 481877.0 5456410 94.29034
4 104 481879.9 5456425 94.25546
5 105 481872.7 5456424 94.09370
After looking through several posts and trying to use functions in several libraries, I still cannot figure out a way to properly plot the surface. I've tried the following:
library(plotly)
plot_ly( y= Y, x = X, z = Z, data=p, type = "surface") #returns empty graphic frame
PX = data.matrix(p$X)
PY = data.matrix(p$Y)
PZ = data.matrix(p$Z)
library(plot3D)
surf3D(PX, PY, PZ)
#returns: Error in if (is.na(var)) ispresent <- FALSE else if (length(var) == 1) if (is.logical(var)) if (!var) ispresent <- FALSE :
argument is of length zero
library(lattice)
wireframe(p$Z ~ p$X*p$Y, data = p) #returns just a cube
library(rgl)
surface3d(p$X,p$Y,p$Z)
#returns: Error in rgl.surface(x = c(481897.916, 481888.8482, 481876.9524, 481879.9393, : y' length != 'x' rows * 'z' cols;
#although there are 60 data points in the form (X,Y,Z) in the data set, with no points missing any coordinate
I must have been doing something horribly wrong here. Would anyone mind to point out what the mistake is?
You cannot make a 3D surface plot with this data because to do it you have to have Z value for each (X,Y) couple, like this :
X1 X2 X3 ... Xn
Y1 Z11 Z12 Z13 ... Z1n
Y2 Z21 Z22 Z23 ... Z2n
Y3 Z31 Z32 Z33 ... Z3n
. .
. .
. .
Ym Zm1 Zm2 Zm3 ... Zmn
For example you don't have Z value for (481897.9,5456417) couple.
So, all you can do is a scatter3d plot :
plot_ly(data = p,x = X,y = Y, z = Z,type = "scatter3d",showlegend = FALSE)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.