简体   繁体   English

在R的网格包中添加3D abline到云图

[英]Add 3D abline to cloud plot in R's lattice package

I want to add a 3D abline to a cloud scatterplot in R's lattice package. 我想在R的网格包中为一个云散点图添加一个3D基线。 Here's a subset of my data (3 variables all between 0,1): 这是我的数据的一个子集(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))

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 (ie, diagonally through the plot). 我想在0,0,0和1,1,1之间添加一条虚线灰色线(即,对角线穿过图)。 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. 我知道我可以使用“type =”l“,panel.3d.cloud = panel.3dscatter”将点更改为行,但是我看不到使用此方法向绘图添加额外点/线的方法。

Here's an example of what I want to achieve using scatterplot3d: 这是我想用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). 我想用云图来控制我查看绘图的角度(scatterplot3d不允许我让绘图的0,0,0角落面对)。 Thanks for any suggestions. 谢谢你的任何建议。

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. 在这个(编辑过的)版本中, do.call(panel.cloud,L)是第一个,因此这些点会do.call(panel.cloud,L)该行而不是反之亦然。 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. 如果你想隐藏线删除,那么我相信rgl是你唯一的选择...非常强大但不是很漂亮,并且具有更原始的界面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM