使用 scatterplot3d 绘制薄板样条 [英] Plot a thin plate spline using scatterplot3d

查看:25
本文介绍了使用 scatterplot3d 绘制薄板样条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

样条曲线对我来说还是比较新的.

我想弄清楚如何创建薄板样条的三维图,类似于统计学习简介(

scatterplot3d 包中没有surface3d 函数.(我刚刚搜索了 Rhelp 档案,看看我是否遗漏了什么,但图形专家总是说你需要使用 lattice::wireframegraphics::persp 或 'rgl'-package 函数.由于您已承诺使用 scatterplot3d,因此我认为最简单的转换不是转换为那些,而是转换为功能更强大的名为 plot3d 的基础图形包.它具有多种变体和用它的 surf3D 制作非常漂亮的表面功能:

Splines are still fairly new to me.

I am trying to figure out how to create a three dimensional plot of a thin plate spline, similar to the visualizations which appear on pages 24-25 of Introduction to Statistical Learning (http://www-bcf.usc.edu/~gareth/ISL/ISLR%20Sixth%20Printing.pdf). I'm working in scatterplot3d, and for the sake of easily reproducible data, lets use the 'trees' dataset in lieu of my actual data.

Setting the initial plot is trivial:

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

I use the Tps function from the fields library to create the spline:

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

And I can begin to represent the spline visually:

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

But when I try to complete the spline by cross hatching lines along the height access, the results become problematic:

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 

And the more that I look at the resulting plot, the less certain I am that I'm even using the right data from my.spline.

Please note that this project uses scatterplot3d for other visualizations, so I am wedded to this package as the result of preexisting team choices. Any help will be greatly appreciated.

解决方案

I don't think you are getting the predicted Tps. That requires using 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")

You can add back the predicted points. This gives a better idea of x-y regions where there is "support" for the estimated surface:

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

There is no surface3d function in scatterplot3d package. (And I just searched the Rhelp archives to see if I were missing something but the graphics experts have always said that you would need to use lattice::wireframe, the graphics::persp or the 'rgl'-package functions. Since you have made a commitment to scatterplot3d, I think the easiest transtion would not be to those but to the much more capable base-graphics package named plot3d. It is capable of many variations and makes quite beautiful surfaces with its surf3D function:

这篇关于使用 scatterplot3d 绘制薄板样条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆