【问题标题】:How to draw two 3d graphs (one on top of another) in R using scatterplot?如何使用散点图在 R 中绘制两个 3d 图(一个在另一个之上)?
【发布时间】:2015-04-08 11:34:37
【问题描述】:

我确定这是一个非常简单的问题,但不知何故我找不到答案。所以在 2D 中,如果我想显示最高实际值的预测,我会这样做:

plot(x, y, type = “l”, col = “green")
lines(x`, y`, type = “l”, col = "blue")

但我不知道如何在 3d 中执行此操作(我正在使用 scatterplot3d) 我设法显示实际值

s3d<-scatterplot3d(x, y, z, color = “blue”, type = “l”, …)
s3d.coords <- s3d$xyz.convert(x,y,z)
D3_coord=cbind(s3d.coords$x,s3d.coords$y)

但是如何在此之上绘制预测值的图表?
提前谢谢你。

【问题讨论】:

    标签: r graphics plot


    【解决方案1】:

    我不确定这是否是您想要的,但这里有一个选项(注意作为 scatterplot3d 输入的不同数据结构 - z 的向量而不是矩阵):

    library(scatterplot3d)
    
    n <- 10
    x <- seq(-10,10,,n)
    y <- seq(-10,10,,n)
    grd <- expand.grid(x=x,y=y)
    z <- matrix(2*grd$x^3 + 3*grd$y^2, length(x), length(y))
    image(x, y, z, col=rainbow(100))
    plot(x, y, type = "l", col = "green")
    
    X <- grd$x
    Y <- grd$y
    Z <- 2*X^3 + 3*Y^2
    s3d <- scatterplot3d(X, Y, Z, color = "blue", pch=20)
    s3d.coords <- s3d$xyz.convert(X, Y, Z)
    D3_coord=cbind(s3d.coords$x,s3d.coords$y)
    lines(D3_coord, t="l", col=rgb(0,0,0,0.2))
    

    【讨论】:

    • 为什么我们需要一个 z 矩阵?
    • 你不知道 - 这只是为了说明。 scatterplot3d 函数只需要 3 个向量(例如 XYZ)。
    • 您能否更新您的示例,使两个图形具有不同的颜色?如果不是太麻烦的话。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-03
    相关资源
    最近更新 更多