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.