我想通过scatterplot3d绘制响应面,但是下面的代码会出现错误。
library(rsm)
swiss2.lm <- lm(Fertility ~ poly(Agriculture, Education, degree = 2), data = swiss)
persp(swiss2.lm, Education ~ Agriculture, zlab = "Fertility")
library(scatterplot3d)
s3d <-
scatterplot3d(
swiss
# , type = "h"
, highlight.3d = TRUE
, angle = 55
, scale.y = 0.7
, pch = 16
)
s3d$plane3d(swiss2.lm, lty.box = "solid")如果你能帮忙解决这个问题,我会非常感激的。谢谢
Eidt
Error in segments(x, z1, x + y.max * yx.f, z2 + yz.f * y.max, lty = ltya, :
cannot mix zero-length and non-zero-length coordinates我正在使用来自swiss库的rsm数据。
发布于 2012-11-26 22:24:20
你是如何使用scatterplot3d的?如果你愿意在rgl上做这件事,那是相当容易的。以下是您的示例:
建立均匀间隔的网格并进行预测:
newdat <- expand.grid(Education=seq(0,50,by=5),
Agriculture=seq(0,100,by=10))
newdat$pp <- predict(swiss2.lm,newdata=newdat)绘制点并添加曲面:
library(rgl)
with(swiss,plot3d(Agriculture,Education,Fertility))
with(newdat,surface3d(unique(Agriculture),unique(Education),pp,
alpha=0.3,front="line"))
rgl.snapshot("swiss.png")

rgl有一些优点(隐藏线去除,照明效果,动态旋转和缩放)和一些缺点(不适合基本包布局等;更难操作字体,包括plotmath方程等;更难调整标签布局和情节风格)。scatter3d函数在car包中有一些很好的特性,可以将回归曲面添加到rgl图中,但据我所见,它可以建立加性模型,但不允许二次多项式模型。
据我所见,为了在scatterplot3d框架中这样做,您必须构造回归曲面中与四边形对应的点,并使用xyz.convert和segments绘制它们.
https://stackoverflow.com/questions/13570792
复制相似问题