我想创建一个湖泊深度的交互式 3D 表面图,最好使用plotly
or rgl
图书馆。我已经从一个中提取了我的数据SpatialLinesDataFrame
Gauss-Krueger/EPSG:31468 CRS 中的等高线,即公制单位。现在,每条轮廓线都会生成一组具有相同深度值的坐标。生成的数据框相当大,但看起来像这样:
set.seed(41)
xx <- rnorm(100,4448929,100)
yy <- rnorm(100,5308097,100)
zz <- c(rep(-10,10),rep(-20,10),rep(-30,10),rep(-40,10),rep(-50,10),rep(-60,10),rep(-70,10),rep(-80,10),rep(-90,10),rep(-100,10))
df <- data.frame(xx,yy,zz)
我尝试用绘制数据plotly
as in this https://plot.ly/r/3d-surface-plots/示例和rgl
as in this https://stackoverflow.com/questions/1896419/plotting-a-3d-surface-plot-with-contour-map-overlay-using-r邮政。在这两种情况下,我都会收到与数据不是矩阵格式相关的错误消息,即 x 和 y 值表示为行号和列号。
什么有效,是使用add_trace
命令输入plotly
:
plot_ly() %>% add_trace(df,x = ~df$xx, y = ~df$yy, z = ~df$zz,type="mesh3d")
然而,生成的图表不仅缺少花哨的颜色图例add_surface
命令,但更重要的是,相对于 z 值扭曲 x 和 y 值。尽管 z 值都具有相同的公制单位,但显示的 z 值太大。
我还尝试将数据框重塑为矩阵,如下所示this https://stackoverflow.com/questions/9617348/reshape-three-column-data-frame-to-matrix-long-to-wide-format帖子,但它要么根本不起作用,要么给我一个几乎完全由 NA 组成的矩阵。我只能推测,与该范围内的所有 x-y 坐标组合相比,附加深度值的坐标数量非常小?
任何建议将不胜感激 - 谢谢!