MYa*_*208 2 r graph scatter-plot
我想通过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")
Run Code Online (Sandbox Code Playgroud)
如果您能帮助解决问题,我将非常感谢.谢谢
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
Run Code Online (Sandbox Code Playgroud)
我正在使用库中的swiss数据rsm.
你如何使用scatterplot3d?如果你愿意这样做rgl很容易.以下是您的示例:
设置均匀间隔的网格并进行预测:
newdat <- expand.grid(Education=seq(0,50,by=5),
Agriculture=seq(0,100,by=10))
newdat$pp <- predict(swiss2.lm,newdata=newdat)
Run Code Online (Sandbox Code Playgroud)
绘制点并添加曲面:
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")
Run Code Online (Sandbox Code Playgroud)

rgl有一些优点(隐藏线删除,灯光效果,动态旋转和缩放)和一些缺点(不适合基础包布局等;更难操纵字体,包括plotmath方程等;更难调整标签位置和情节风格).包中的scatter3d函数car有一些很好的功能,可以将回归曲面添加到rgl绘图中,但据我所知,它可以添加模型,但不允许二次多项式模型...
据我所知,为了在scatterplot3d框架中执行此操作,您必须构建与回归表面中的四边形对应的点,并使用xyz.convert和segments绘制它们......
| 归档时间: |
|
| 查看次数: |
4610 次 |
| 最近记录: |