在R的点阵包中向云图添加3D缩写 [英] Add 3D abline to cloud plot in R's lattice package

查看:172
本文介绍了在R的点阵包中向云图添加3D缩写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在R的晶格封装中向云散点图添加3D斜线.这是我的数据的子集(3个变量都在0.1之间):

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))

这是云图:

# 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将点更改为线,但是我看不到添加额外点/线的方法使用此图.

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.

以下是我要使用scatterplot3d实现的示例:

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)

我想用一个云图来做到这一点,以控制查看图的角度(scatterplot3d不允许我面对图的0,0,0角).感谢您的任何建议.

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.

推荐答案

不雅且可能很脆弱,但这似乎可行...

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(...)
      })

要记住的一件事是,这不会删除隐藏的点/线,因此,线将位于所有点的前面或后面.在此(已编辑)版本中,do.call(panel.cloud,L)是第一个,因此点将使直线模糊而不是相反.如果您想删除隐藏线,那么我相信rgl是您唯一的选择……功能非常强大,但外观却不那么漂亮,并且界面更加原始.

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.

这篇关于在R的点阵包中向云图添加3D缩写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆