繁体   English   中英

使用scatterplot3d绘制薄板样条

[英]Plot a thin plate spline using scatterplot3d

花键对我来说还是很新的。

我试图弄清楚如何创建薄板样条的三维图,类似于《统计学习入门》( http://www-bcf.usc.edu/~gareth /ISL/ISLR%20Sixth%20Printing.pdf )。 我正在使用scatterplot3d,为了容易复制数据,让我们使用“树”数据集代替我的实际数据。

设置初始图很简单:

data(trees)
attach(trees)
s3d <- scatterplot3d(Girth, Height, Volume,
                 type = "n", grid = FALSE, angle = 70,
                 zlab = 'volume',
                 xlab = 'girth', 
                 ylab = 'height',
                 main = "TREES") # blank 3d plot

我使用来自字段库的Tps函数来创建样条线:

my.spline <- Tps(cbind(Girth, Height), Volume)

我可以开始用视觉表示样条线:

for(i in nrow(my.spline$x):1) # for every girth . . .
s3d$points3d(my.spline$x[,1], rep(my.spline$x[i,2], times=nrow(my.spline$x)), # repeat every height . . . 
              my.spline$y, type='l') # and match these values to a predicted volume

但是,当我尝试通过沿高度通道的剖面线完成样条线时,结果将出现问题:

for(i in nrow(my.spline$x):1) # for every height . . .
s3d$points3d(rep(my.spline$x[i,1], times=nrow(my.spline$x)), my.spline$x[,2],  # repeat every girth . . . 
           my.spline$y, type='l') # and match these values to a predicted volume 

而且,我对结果图的关注程度越高,就越不确定我使用的是来自my.spline的正确数据。

请注意,该项目将scatterplot3d用于其他可视化,因此由于预先存在的团队选择,我被此软件包所束缚。 任何帮助将不胜感激。

我认为您没有获得预期的Tps。 那需要使用predict.Tps

require(fields)
require(scatterplot3d)
data(trees)
attach(trees)   # this worries me. I generally use data in dataframe form.
s3d <- scatterplot3d(Girth, Height, Volume,
                 type = "n", grid = FALSE, angle = 70,
                 zlab = 'volume',
                 xlab = 'girth', 
                 ylab = 'height',
                 main = "TREES") # blank 3d plot
grid<- make.surface.grid( list( girth=seq( 8,22), height= seq( 60,90) ))
surf <- predict(my.spline, grid)
 str(surf)
# num [1:465, 1] 5.07 8.67 12.16 15.6 19.1 ...
str(grid)
#------------
 int [1:465, 1:2] 8 9 10 11 12 13 14 15 16 17 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:2] "girth" "height"
 - attr(*, "grid.list")=List of 2
  ..$ girth : int [1:15] 8 9 10 11 12 13 14 15 16 17 ...
  ..$ height: int [1:31] 60 61 62 63 64 65 66 67 68 69 ...
#-------------
s3d$points3d(grid[,1],grid[,2],surf, cex=.2, col="blue")

您可以添加预测点。 这样可以更好地了解xy区域,其中存在对估计曲面的“支持”:

s3d$points3d(my.spline$x[,1], my.spline$x[,2],  
           predict(my.spline) ,col="red")

在此处输入图片说明

scatterplot3d软件包中没有surface3d函数。 (我只是搜索了Rhelp档案,以查看是否遗漏了一些东西,但是图形专家一直说您将需要使用graphics::persp lattice::wireframegraphics::persp或'rgl'-package函数。做出了对scatterplot3d的承诺,我认为最简单的转换不是到那些,而是到功能更强大的名为plot3d的基本图形包,它具有多种变体,并具有surf3D功能可以制作出漂亮的表面:

暂无
暂无

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

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