[R] Dampening the spline interpolation for contours
Spencer Graves
spencer.graves at structuremonitoring.com
Tue Sep 14 00:02:07 CEST 2010
Have you considered something like the following:
install.packages('sos') # if it's not already installed
library(sos)
si <- findFn('spline interpolation')
# 125 matches
summary(si)
# in 64 packages
si
# opens the results as a table in a web browser
# sorted to put first the package with the most matches
# with links to all 125 help pages
However, from my understanding of your problem, I'd suggest you
do functional regression followed by contour of the fitted model. The
best reference I know for this is chapter 9 on "Functional Linear Models
for Scalar Responses" in Ramsay, Hooker and Graves (2009) Functional
Data Analysis with R and Matlab (Springer). That does not contain a
contour plot example, but it will give you a model. You can then use
"expand.grid" to create a data.frame of points on a grid, which you can
feed with the model to "predict.fRegress" to get plotting levels. The
output of "predict" can then be fed to "contour" to produce what you
want, I think. I'm sorry I don't have time now to fill in the details.
Hope this helps.
Spencer Graves
p.s. Disclaimer: I'm the lead author of the "sos" package and third
author on the Functional Data Analysis book cited above.
On 9/13/2010 2:06 PM, Dylan Beaudette wrote:
> Although not an R solution, I would highly recommend the generic mapping tools
> GMT for this type of work.
>
> http://gmt.soest.hawaii.edu/
>
> Cheers,
> Dylan
>
> On Monday 13 September 2010, Craig Stanton wrote:
>> Hello all,
>> I'm very new to R and am having some trouble with the results of the
>> interp function. I'm trying to produce a chart roughly akin to a weather
>> map with natural looking filled contours over a large region of the south
>> pacific. I've got a list of points and values to be mapped to those points
>> and I use the interp function as follows:
>>
>> tab<-read.table("data.txt")
>> library("akima")
>> png("contour.png", width = 1000, height=500)
>> colourRange<-colorRampPalette(c("#f9cd00","#f9cd00","#f9cd00","#f9cd00","#f
>> fffff","#6afaff","#53a3ff","#53a3ff","#53a3ff"))
>> filled.contour(interp(x=tab$V1,tab$V2, tab$V3, xo=seq(min(tab$V1),
>> max(tab$V1),length=1000),yo=seq(min(tab$V2), max(tab$V2),length=500),
>> linear = FALSE), xlim = range(160,190),ylim = range(-30,-10),
>> zlim=c(-4,4),color.palette = colourRange ) dev.off()
>> rm(list = ls())
>>
>>
>>
>> I have added the "rm(list=ls())" on the end to try to reset the workspace
>> because I've found that repeated running of this code can result in
>> different output images. The main problem I am having is that though my
>> values are all between -2.5 and 2.5 the interpolation gives me values well
>> outside that range. Usually shown by colouring the areas white but
>> confirmed by plotting a regular contour map instead of a filled contour.
>> What I'd like to find out is if there is a way to dampen the cubic spline
>> that is being used, or if there is an alternative to interp() that I should
>> be looking at. Like I said before, I'm very new to R, so I may have missed
>> something entirely obvious.
>>
>> Thanks in advance,
>> Craig
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html and provide commented, minimal,
>> self-contained, reproducible code.
>
>
--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph: 408-655-4567
More information about the R-help
mailing list