简体   繁体   English

R 中没有点的回归平面的 3D 图

[英]3D plot of regression plane without points in 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)

I'm trying to plot a regression plane that shows how temperature moderates the relationship between nitrogen and soil .我试图绘制一个回归平面,显示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")

This will plot the regression plane with points, but I would like to plot it without points.这将绘制带点的回归平面,但我想不带点绘制它。 Omitting x, y, z when calling the scatter3D() function results in an error.调用scatter3D()函数时省略x, y, z导致错误。

Here's a wild idea.这是一个疯狂的想法。 Try setting cex = 0 .尝试设置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")

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM