简体   繁体   English

用于R中响应面的scatterplot3d

[英]scatterplot3d for Response Surface in R

I want to graph response surface through scatterplot3d but the following code through an error. 我想通过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")

I'd highly appreciate if you help to figure out the issue. 如果您能帮助解决问题,我将不胜感激。 Thanks 谢谢

Eidt 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

I'm using swiss data from rsm library. 我正在使用来自rsm库的swiss数据。

How attached are you to using scatterplot3d ? 您对scatterplot3d重视程度如何? If you're willing to do it in rgl it's pretty easy. 如果您愿意在rgl进行操作,这很简单。 Following from your example: 以下是您的示例:

Set up evenly spaced grid and make predictions: 设置均匀间隔的网格并进行预测:

newdat <- expand.grid(Education=seq(0,50,by=5),
            Agriculture=seq(0,100,by=10))
newdat$pp <- predict(swiss2.lm,newdata=newdat)

Plot points and add surface: 绘制点并添加表面:

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 has some advantages (hidden line removal, lighting effects, dynamic rotation and zooming) and some disadvantages (doesn't fit well into base-package layouts etc.; harder to manipulate fonts, include plotmath equations, etc.; harder to adjust label placement and plot style). rgl具有一些优点(隐藏线去除,照明效果,动态旋转和缩放)和一些缺点(不适用于基本包装布局等);更难于操纵字体,包括plotmath方程等;更难于调整标签放置和绘图样式)。 The scatter3d function in the car package has some nice features for adding regression surfaces to an rgl plot, but as far as I can see it does additive models, but doesn't allow for quadratic polynomial models ... car包装中的scatter3d函数具有一些不错的功能,可以将回归曲面添加到rgl图中,但是据我所知,它具有加法模型,但不允许二次多项式模型...

As far as I can see, in order to do this in the scatterplot3d framework you would have to construct the points corresponding to the quadrangles in the regression surface and use xyz.convert and segments to draw them ... 据我所知,为了在scatterplot3d框架中执行此操作,您将必须构造与回归曲面中的四边形相对应的点,并使用xyz.convertsegments来绘制它们。

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

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