【问题标题】:3D surface plot in R, given x,y,z coordinatesR中的3D曲面图,给定x,y,z坐标
【发布时间】:2016-09-07 02:34:19
【问题描述】:

我有以下数据集,需要根据这组数据(60 个 3D 点)绘制曲面。这里X、Y为水平面坐标,Z为垂直/高度坐标。

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

在浏览了几篇文章并尝试使用多个库中的函数后,我仍然无法找到正确绘制曲面的方法。我尝试了以下方法:

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

我一定在这里做错了什么。有人介意指出错误是什么吗?

【问题讨论】:

  • 尝试使用 rgl::plot3d(p$X,p$Y,p$Z) 绘制 3D 散点图。此外,如果您可以使用 dput 命令发布您的数据,那么其他人可以更轻松地提供帮助。

标签: r csv plot 3d


【解决方案1】:

您不能使用此数据制作 3D 曲面图,因为要做到这一点,您必须为每个 (X,Y) 对设置 Z 值,如下所示:

   X1  X2  X3  ... Xn
Y1 Z11 Z12 Z13 ... Z1n
Y2 Z21 Z22 Z23 ... Z2n
Y3 Z31 Z32 Z33 ... Z3n
.                   .
.                   .
.                   .
Ym Zm1 Zm2 Zm3 ... Zmn

例如,您没有 (481897.9,5456417) 对的 Z 值。

所以,你所能做的就是一个 scatter3d 图:

plot_ly(data = p,x = X,y = Y, z = Z,type = "scatter3d",showlegend = FALSE)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    相关资源
    最近更新 更多