绘制无点回归平面-R

loc*_*cus 1 plot regression r

dat <- data.frame(nitrogen = runif(50, 0, 10), temperature= rnorm(50, 10, 3))
modmat <- model.matrix(~ nitrogen * temperature, dat)
coeff <- c(1, 2, -1, 1.5)
dat$soil <- rnorm(50, mean = modmat %*% coeff, sd = 0.5)
Run Code Online (Sandbox Code Playgroud)

我试图绘制回归平面,显示了如何temperature温和派之间的关系nitrogensoil

library(plot3D)

x <- dat$nitrogen
y <- dat$temperature
z <- dat$soil

fit <- lm(z ~ x*y)

grid.lines = 26
x.pred <- seq(min(x), max(x), length.out = grid.lines)
y.pred <- seq(min(y), max(y), length.out = grid.lines)
xy <- expand.grid( x = x.pred, y = y.pred)
z.pred <- matrix(predict(fit, newdata = xy), 
                 nrow = grid.lines, ncol = grid.lines)

fitpoints <- predict(fit)

scatter3D(x, y, z, pch = 18, cex = 2, 
    theta = 20, phi = 20, ticktype = "detailed",
    xlab = "nitrogen", ylab = "soil", zlab = "temperature",  
    surf = list(x = x.pred, y = y.pred, z = z.pred,  
    facets = NA, fit = fitpoints), main = "dat")
Run Code Online (Sandbox Code Playgroud)

这将绘制带有点的回归平面,但是我想绘制没有点的回归平面。x, y, z调用scatter3D函数时省略会导致错误。

Rom*_*rik 6

这是一个疯狂的主意。尝试设置cex = 0

scatter3D(x, y, z, pch = 18, cex = 0, 
    theta = 20, phi = 20, ticktype = "detailed",
    xlab = "nitrogen", ylab = "soil", zlab = "temperature",  
    surf = list(x = x.pred, y = y.pred, z = z.pred,  
    facets = NA, fit = fitpoints), main = "dat")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

  • 另一个疯狂的想法是设置`pch = NA` (2认同)