Scatterplot3d - 调整 polygon/plane 的大小

Scatterplot3d - resizing the polygon/plane

这是一个使用来自 ISLR 的数据集 College 的示例:

library(scatterplot3d)
library(ISLR)
attach(College)

s3d <- scatterplot3d(x=Top10perc, y=S.F.Ratio, z=PhD)
my.lm <- lm(Top10perc ~ S.F.Ratio + PhD)
plane <- s3d$plane3d(my.lm, lty.box = "solid", draw_polygon = TRUE)

我想增加灰色多边形(平面)的大小。来自 scatterplot3d 文档:

The arguments draw_lines and draw_polygon allow for choosing whether to represent the plane via line segments or as a solid surface, respectively. The list in polygon_args collects arguments to be passed to the underlying polygon call that draws a solid (or transparent) plane if draw_polygon=TRUE.

polygon函数:

polygon(x, y = NULL, density = NULL, angle = 45, border = NULL, col = NA, lty = par("lty"), ..., fillOddEven = FALSE)

我想我需要更改基础 polygon 调用中的 xy 参数,但我该怎么做?我可以访问它们吗?

我认为你画错了平面。文档有点稀疏,但似乎 s3d$plane3d 假设 z 是响应变量,x 是第一个预测变量,y 是第二个预测变量。但即使我更改您的代码以使用这些假设,例如

library(scatterplot3d)
library(ISLR)

s3d <- with(College, scatterplot3d(z=Top10perc, x=S.F.Ratio, y=PhD))
my.lm <- lm(Top10perc ~ S.F.Ratio + PhD, data = College)
plane <- s3d$plane3d(my.lm, lty.box = "solid", draw_polygon = TRUE)

我没有找到好的情节:

似乎 scatterplot3d 没有在边界框的边界处剪裁平面。

我使用 rgl

获得了更好的飞机
library(rgl)
library(ISLR)

with(College, plot3d(x=Top10perc, y=S.F.Ratio, z=PhD))
my.lm <- lm(Top10perc ~ S.F.Ratio + PhD, data = College)
coefs <- coef(my.lm)
planes3d(a = -1, b = coefs["S.F.Ratio"], c = coefs["PhD"], d = coefs["(Intercept)"],
         alpha = 0.2)

绘图可以旋转,但看起来不如 scatterplot3d 输出(平面上没有网格),并且更难绘制:不支持 lm() 结果在 rgl::planes3d 中,因此您需要仔细阅读帮助页面。也许其他人可以提供更好的选择。