将 3D abline 添加到 R 的点阵包中的云图中

发布于 2024-12-09 00:13:24 字数 1356 浏览 0 评论 0原文

我想将 3D abline 添加到 R 格子包中的云散点图。这是我的数据的子集(3 个变量均在 0,1 之间):

dat <- structure(c(0.413, 0.879, 0.016, 0.631, 0.669, 0.048, 1, 0.004, 0.523, 0.001, 
0.271, 0.306, 0.014, 0.008, 0.001, 0.023, 0.670, 0.027, 0.291, 0.709, 
0.002, 0.003, 0.611, 0.024, 0.580, 0.755, 1, 0.003, 0.038, 0.143, 0.214, 
0.161, 0.008, 0.027, 0.109, 0.026, 0.229, 0.006, 0.377, 0.191, 0.724, 
0.119, 0.203, 0.002, 0.309, 0.011, 0.141, 0.009, 0.340, 0.152, 0.545, 
0.001, 0.217, 0.132, 0.839, 0.052, 0.745, 0.001, 1, 0.273), .Dim = c(20L, 3L))

这是云图:

# cloud plot
trellis.par.set("axis.line", list(col="transparent")) 
cloud(dat[, 1] ~ dat[, 2] + dat[, 3], pch=16, col="darkorange", groups=NULL, cex=0.8, 
    screen=list(z = 30, x = -70, y = 0),
    scales=list(arrows=FALSE, cex=0.6, col="black", font=3, tck=0.6, distance=1) ) 

我想在 0,0,0 和 1,1,1 之间添加一条灰色虚线(即对角线穿过图)。我知道我可以使用“type =“l”,panel.3d.cloud = panel.3dscatter”将点更改为线,但我看不到添加额外点/线的方法使用这个的情节。

这是我想要使用 scatterplot3d 实现的示例:

# scatterplot3d
s3d <- scatterplot3d(dat, type="p", color="darkorange", angle=55, scale.y=0.7,
    pch=16, col.axis="blue", col.grid="lightblue") 

# add line 
s3d$points3d(c(0,1), c(0,1), c(0,1), col="grey", type="l", lty=2)

我想使用云图来控制查看绘图的角度(scatterplot3d 不允许我拥有绘图的 0,0,0 角)面对)。感谢您的任何建议。

I want to add a 3D abline to a cloud scatterplot in R's lattice package. Here's a subset of my data (3 variables all between 0,1):

dat <- structure(c(0.413, 0.879, 0.016, 0.631, 0.669, 0.048, 1, 0.004, 0.523, 0.001, 
0.271, 0.306, 0.014, 0.008, 0.001, 0.023, 0.670, 0.027, 0.291, 0.709, 
0.002, 0.003, 0.611, 0.024, 0.580, 0.755, 1, 0.003, 0.038, 0.143, 0.214, 
0.161, 0.008, 0.027, 0.109, 0.026, 0.229, 0.006, 0.377, 0.191, 0.724, 
0.119, 0.203, 0.002, 0.309, 0.011, 0.141, 0.009, 0.340, 0.152, 0.545, 
0.001, 0.217, 0.132, 0.839, 0.052, 0.745, 0.001, 1, 0.273), .Dim = c(20L, 3L))

Here's the cloud plot:

# cloud plot
trellis.par.set("axis.line", list(col="transparent")) 
cloud(dat[, 1] ~ dat[, 2] + dat[, 3], pch=16, col="darkorange", groups=NULL, cex=0.8, 
    screen=list(z = 30, x = -70, y = 0),
    scales=list(arrows=FALSE, cex=0.6, col="black", font=3, tck=0.6, distance=1) ) 

I want to add a dashed grey line between 0,0,0 and 1,1,1 (i.e., diagonally through the plot). I know I can change the points to lines using "type="l", panel.3d.cloud=panel.3dscatter", but I can't see a way to add extra points/lines to the plot using this.

Here's an example of what I want to achieve using scatterplot3d:

# scatterplot3d
s3d <- scatterplot3d(dat, type="p", color="darkorange", angle=55, scale.y=0.7,
    pch=16, col.axis="blue", col.grid="lightblue") 

# add line 
s3d$points3d(c(0,1), c(0,1), c(0,1), col="grey", type="l", lty=2)

I want to do this with a cloud plot to control the angle at which I view the plot (scatterplot3d doesn't allow me to have the 0,0,0 corner of the plot facing). Thanks for any suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一指流沙 2024-12-16 00:13:24

不优雅而且可能很脆弱,但这似乎有效......

cloud(dat[, 1] ~ dat[, 2] + dat[, 3], pch=16, col="darkorange", 
        groups=NULL, cex=0.8, 
    screen=list(z = 30, x = -70, y = 0),
    scales=list(arrows=FALSE, cex=0.6, col="black", font=3, 
                tck=0.6, distance=1) ,
      panel=function(...) {
        L <- list(...)
        L$x <- L$y <- L$z <- c(0,1)
        L$type <- "l"
        L$col <- "gray"
        L$lty <- 2
        do.call(panel.cloud,L)
        p <- panel.cloud(...)
      })

要记住的一件事是,这不会删除隐藏的点/线,因此线要么位于所有点的前面,要么位于所有点的后面;在此(编辑后的)版本中,do.call(panel.cloud,L) 是第一个,因此点将遮盖线,而不是反之亦然。如果您想要删除隐藏线,那么我相信 rgl 是您唯一的选择......非常强大,但不那么漂亮,并且界面更原始。

Inelegant and probably fragile, but this seems to work ...

cloud(dat[, 1] ~ dat[, 2] + dat[, 3], pch=16, col="darkorange", 
        groups=NULL, cex=0.8, 
    screen=list(z = 30, x = -70, y = 0),
    scales=list(arrows=FALSE, cex=0.6, col="black", font=3, 
                tck=0.6, distance=1) ,
      panel=function(...) {
        L <- list(...)
        L$x <- L$y <- L$z <- c(0,1)
        L$type <- "l"
        L$col <- "gray"
        L$lty <- 2
        do.call(panel.cloud,L)
        p <- panel.cloud(...)
      })

One thing to keep in mind is that this will not do hidden point/line removal, so the line will be either in front of all of the points or behind them all; in this (edited) version, do.call(panel.cloud,L) is first so the points will obscure the line rather than vice versa. If you want hidden line removal then I believe rgl is your only option ... very powerful but not as pretty and with a much more primitive interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文