【问题标题】:How to create a 3 D surface plot如何创建 3D 曲面图
【发布时间】:2013-12-20 10:18:18
【问题描述】:

我有 x、y 和 z 数据的独特组合,想创建 3d 散点图和曲面图。 3d 散点图使用以下代码:

s3d <-scatterplot3d(x,z,y, pch=16, highlight.3d=TRUE, type="h", main="3D Scatterplot")

但我无法使用基本图形创建曲面图。 persp(x, z, y) 给了我错误信息:“期望增加 'x' 和 'y' 值。

我也试过rgl包rgl包:

require(rgl)  
surface3d(x, y, z)

导致“rgl.surface(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, : y 长度 != x 行 * z 列"

我看过以前的帖子herehere,但大多数都需要对数据进行一些更改或插值。如何在不更改/大量更改内容的情况下使用示例数据创建 3d 曲面图。

示例数据如下:

dput(df)
structure(list(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), z = c(1, 2, 3, 
4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10), y = c(0.300000041723251, 0.400000065565109, 
0.499999970197678, 0.600000023841858, 0.700000047683716, 0.800000071525574, 
1.20000004768372, 1.59999990463257, 1.99999988079071, 2.39999985694885, 
1.40000009536743, 1.60000002384186, 1.79999983310699, 1.99999988079071, 
2.19999980926514, 2.39999985694885, 3, 3.59999990463257, 4.19999980926514, 
4.79999971389771, 2.49999976158142, 2.79999971389771, 3.09999990463257, 
3.39999961853027, 3.69999980926514, 4, 4.79999971389771, 5.59999990463257, 
6.39999961853027, 7.19999980926514, 3.59999990463257, 4, 4.39999961853027, 
4.79999971389771, 5.19999980926514, 5.59999990463257, 6.59999990463257, 
7.59999942779541, 8.60000038146973, 9.60000038146973, 4.69999980926514, 
5.19999980926514, 5.69999980926514, 6.19999980926514, 6.69999980926514, 
7.19999980926514, 8.40000057220459, 9.60000038146973, 10.8000011444092, 
12.0000009536743)), datalabel = "", time.stamp = "19 Dec 2013 17:54", .Names = c("x", 
"z", "y"), formats = c("%9.0g", "%9.0g", "%9.0g"), types = c(254L, 
254L, 254L), val.labels = c("", "", ""), var.labels = c("", "", 
""), version = 12L, row.names = c("1", "2", "3", "4", "5", "6", 
"7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", 
"18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", 
"29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", 
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"
), class = "data.frame")

【问题讨论】:

    标签: r 3d plot


    【解决方案1】:

    我假设你的 y & z 列是倒置的,但你可以这样做 - 基本上你需要 x & y 作为坐标轴,z-grid 作为相交值:

    require(rgl)
    require(reshape2)
    df.x<-unique(df$x)
    df.y<-unique(df$z)
    df.z<-acast(df,x~z)
    persp(df.x,df.y,df.z)
    surface3d(df.x,df.y,df.z)
    

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 2021-12-06
      • 2020-09-23
      • 2019-10-02
      • 2018-07-06
      • 2017-11-17
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      相关资源
      最近更新 更多