scatterplot3d在 R 中使用,我试图从观察到回归平面绘制红线:
wh <- iris$Species != "setosa"
x <- iris$Sepal.Width[wh]
y <- iris$Sepal.Length[wh]
z <- iris$Petal.Width[wh]
df <- data.frame(x, y, z)
LM <- lm(y ~ x + z, df)
library(scatterplot3d)
G <- scatterplot3d(x, z, y, highlight.3d = FALSE, type = "p")
G$plane3d(LM, draw_polygon = TRUE, draw_lines = FALSE)
Run Code Online (Sandbox Code Playgroud)
要获得下图的 3D 等效项:
在 2D 中,我可以使用segments:
pred <- predict(model)
segments(x, y, x, pred, col = 2)
Run Code Online (Sandbox Code Playgroud)
但是在 3D 中,我对坐标感到困惑。