scatterplot3d: regression plane with residuals
Using scatterplot3d in R, I'm trying to draw red lines from the observations to the regression plane: 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) To obtain the 3D equivalent of the following picture: In 2D, I could just use segments : pred <- predict(model) segments(x, y, x, pred, col = 2) But in 3D I got confused with the coordinates. Using