我无法使scatter3D函数在R中工作。我想绘制一个表面,但是无法使代码运行,尽管对于我在网上找到的某些对象来说很简单。我已经尝试阅读CRAN代码文档,但是却无所适从。我想运行我的代码。
本质上来说,我输入的某些变量存在问题,但我看不到哪里。我认为它可能隐藏在函数内部,而错误消息实际上并不适合我。
任何帮助将不胜感激。
代码:
library("plot3D")
w <- 1:100
sigma <- 5
x <- w + rnorm(w, w, 2*sigma)
y <- w + rnorm(w, w, sigma)
z<- w + rnorm(w, w, 3*sigma)
a <- c()
for (i in 1:10){
a <- c(a, rep(10*i, times = 10))
}
b <- rep(seq(10, 100, 10), times = 10)
ratio = 0.4
d = ratio*a + (1 - ratio)*b + rnorm(100, 0, 10)
fit <- lm(d ~ a + b)
grid.lines = 26
a.pred <- seq(min(a), max(a), length.out = grid.lines)
b.pred <- seq(min(b), max(b), length.out = grid.lines)
ab <- expand.grid(a = a.pred, b = b.pred)
d.pred <- matrix(predict(fit, newdata = ab),
nrow = grid.lines, ncol = grid.lines)
fitpoints <- predict(fit)
scatter plot with regression plane
scatter3D(a,b,d, pch = 18, cex = 2,
theta = 20, phi = 20,
surf = list(a=a.pred, b=b.pred, d=d.pred,
facets = F, fit = fitpoints))
错误消息:
Error in addimg(poly = NULL, plist = plist, a = c(10, 13.6, 17.2, 20.8, :
argument 4 matches multiple formal arguments
答案 0 :(得分:1)
我认为您需要调用x,y和z轴:
# scatter plot with regression plane
scatter3D(a,b,d, pch = 18, cex = 2,
theta = 20, phi = 20,
surf = list(x=a.pred, y=b.pred, z=d.pred,
facets = F, fit = fitpoints))
这对我来说很有效。
有关错误修复的评论:
scatter3D
是问题所在。surf = list(...)
。