将平面添加到 scatterplot3d [英] Adding a plane to scatterplot3d

查看:89
本文介绍了将平面添加到 scatterplot3d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x <-norm(500,50,2)y <-norm(500,5,1)z <-范数(500,6,1)s3d <- scatterplot3d(x[z<6], y[z<6], z[z<6], zlim=range(z), color="darkgrey", col.axis="blue",col.grid="lightblue", main="scatterplot3d - 1", pch=20)s3d$plane3d(6,0,0)s3d$points3d(x[z>=6], y[z>=6], z[z>=6], pch=20)

上面的代码告诉我如何在 3d 散点图中添加一个平面z=6".

第一个问题是:我想知道如何添加一个平面,例如x=3"或y=2".

R 帮助文件解释了

plane3d(Intercept, x.coef = NULL, y.coef = NULL, lty = "dashed", lty.box = NULL, ...).可以指定包含 3 个元素的向量来代替 Intercept.

第二个问题是:我还想知道具有 3 个元素的向量"而不是 Intercept 的作用是什么,x.coef 和 y.coef 参数的作用是什么.

解决方案

问题 1:我会使用线性模型来添加平面,正如我所描述的

x <-rnorm(500,50,2)
y <-rnorm(500,5,1)
z <-rnorm(500,6,1)

s3d <- scatterplot3d(x[z<6], y[z<6], z[z<6], zlim=range(z),  color="darkgrey", col.axis="blue",col.grid="lightblue",   main="scatterplot3d - 1", pch=20)
s3d$plane3d(6,0,0)
s3d$points3d(x[z>=6], y[z>=6], z[z>=6], pch=20)

The above code tells me how to add a plane 'z=6' to the 3d scatter plot.

The first question is: I'm wondering how to add a plane such as 'x=3' or 'y=2'.

R help file explains that

plane3d(Intercept, x.coef = NULL, y.coef = NULL, lty = "dashed", lty.box = NULL, ...). Instead of Intercept a vector containing 3 elements can be specified.

The second question is: I also wonder what the 'vector with 3 elements' instead of Intercept does and what is the role of x.coef and y.coef argument.

解决方案

Question 1: I would use a linear model to add planes, as I describe here and as the package authors use in the vignette:

plot3d <- scatterplot3d(x, y, z, ... )
model  <- lm(y ~ x + z)
plot3d$plane3d(model)

You can specify the xyz intercepts manually, but I don't recommend it, as it produces somewhat odd behaviour. You can also construct complex mesh surfaces using the function intended for points, but as the authors state in the vignette:

Note that scatterplot3d is designed to generate scatter plots, not to draw surfaces, is not really user friendly for this purpose, for which we'd typically rather use R's persp function.

Question 2: The vector with three elements is a container for the xyz intercepts. You can specify them manually as you did above with s3d$plane3d(6,0,0). The x and y coefficients appear to be for mapping those two variables onto a plane.

To make specific planes manually, here is a suggestion from Uwe himself:

spd <- scatterplot3d(1:10, 1:10, 1:10)

# xy
spd$plane3d(0.3549896,0,0,lty="dotted")

# yz
x0 <- 5
xyz1 <- spd$xyz.convert(rep(x0, 6), rep(0, 6), seq(0, 10, by=2))
xyz2 <- spd$xyz.convert(rep(x0, 6), rep(10, 6), seq(0, 10, by=2))
segments(xyz1$x, xyz1$y, xyz2$x, xyz2$y, lty="dotted")

xyz1 <- spd$xyz.convert(rep(x0, 6), seq(0, 10, by=2), rep(0, 6))
xyz2 <- spd$xyz.convert(rep(x0, 6), seq(0, 10, by=2), rep(10, 6))
segments(xyz1$x, xyz1$y, xyz2$x, xyz2$y, lty="dotted")

# zx
y0 <- 6
xyz1 <- spd$xyz.convert(rep(0, 6), rep(y0, 6), seq(0, 10, by=2))
xyz2 <- spd$xyz.convert(rep(10, 6), rep(y0, 6), seq(0, 10, by=2))
segments(xyz1$x, xyz1$y, xyz2$x, xyz2$y, lty="dotted")

xyz1 <- spd$xyz.convert(seq(0, 10, by=2), rep(y0, 6), rep(0, 6))
xyz2 <- spd$xyz.convert(seq(0, 10, by=2), rep(y0, 6), rep(10, 6))
segments(xyz1$x, xyz1$y, xyz2$x, xyz2$y, lty="dotted")

The points are first sampled at a regular interval matching the grid in xyz space using their built-in xyz coordinate conversion function, before mapping the segments between them, producing grids:

这篇关于将平面添加到 scatterplot3d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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