R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("akima-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('akima') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "aspline" > > ### * aspline > > flush(stderr()); flush(stdout()) > > ### Name: aspline > ### Title: Univariate Akima interpolation > ### Aliases: aspline > ### Keywords: arith dplot > > ### ** Examples > > ## regular spaced data > x <- 1:10 > y <- c(rnorm(5), c(1,1,1,1,3)) > > xnew <- seq(-1, 11, 0.1) > plot(x, y, ylim=c(-3, 3), xlim=range(xnew)) > lines(spline(x, y, xmin=min(xnew), xmax=max(xnew), n=200), col="blue") > > lines(aspline(x, y, xnew), col="red") > lines(aspline(x, y, xnew, method="improved"), col="black", lty="dotted") > lines(aspline(x, y, xnew, method="improved", degree=10), col="green", lty="dashed") > > ## irregular spaced data > x <- sort(runif(10, max=10)) > y <- c(rnorm(5), c(1,1,1,1,3)) > > xnew <- seq(-1, 11, 0.1) > plot(x, y, ylim=c(-3, 3), xlim=range(xnew)) > lines(spline(x, y, xmin=min(xnew), xmax=max(xnew), n=200), col="blue") > > lines(aspline(x, y, xnew), col="red") > lines(aspline(x, y, xnew, method="improved"), col="black", lty="dotted") > lines(aspline(x, y, xnew, method="improved", degree=10), col="green", lty="dashed") > > ## an example of Akima, 1991 > x <- c(-3, -2, -1, 0, 1, 2, 2.5, 3) > y <- c( 0, 0, 0, 0, -1, -1, 0, 2) > > plot(x, y, ylim=c(-3, 3)) > lines(spline(x, y, n=200), col="blue") > > lines(aspline(x, y, n=200), col="red") > lines(aspline(x, y, n=200, method="improved"), col="black", lty="dotted") > lines(aspline(x, y, n=200, method="improved", degree=10), col="green", lty="dashed") > > > > cleanEx(); ..nameEx <- "interp" > > ### * interp > > flush(stderr()); flush(stdout()) > > ### Name: interp > ### Title: Gridded Bivariate Interpolation for Irregular Data > ### Aliases: interp interp.new interp.old > ### Keywords: dplot > > ### ** Examples > > data(akima) > # linear interpolation > akima.li <- interp(akima$x, akima$y, akima$z) > image(akima.li$x,akima.li$y,akima.li$z) > contour(akima.li$x,akima.li$y,akima.li$z,add=TRUE) > points(akima$x,akima$y) > > # increase smoothness > akima.smooth <- interp(akima$x, akima$y, akima$z, + xo=seq(0,25, length=100), yo=seq(0,20, length=100)) > image(akima.smooth$x,akima.smooth$y,akima.smooth$z) > contour(akima.smooth$x,akima.smooth$y,akima.smooth$z,add=TRUE) > points(akima$x,akima$y) > # use triangulation library to > # show underlying triangulation: > if(library(tripack, logical.return=TRUE)) + plot(tri.mesh(akima),add=TRUE,lty="dashed") > > # use only 15 points (interpolation only within convex hull!) > akima.part <- interp(akima$x[1:15],akima$y[1:15],akima$z[1:15]) > image(akima.part$x,akima.part$y,akima.part$z) > contour(akima.part$x,akima.part$y,akima.part$z,add=TRUE) > points(akima$x[1:15],akima$y[1:15]) > > # spline interpolation, use 5 points to calculate derivatives > # interp gives `linear interpolation not yet implemented with interp.new()' > akima.spl <- interp.old(akima$x, akima$y, akima$z, + xo=seq(0,25, length=100), yo=seq(0,20, length=100),ncp=5) > image(akima.spl$x,akima.spl$y,akima.spl$z) > contour(akima.spl$x,akima.spl$y,akima.spl$z,add=TRUE) > points(akima$x,akima$y) > > # example with duplicate points > data(airquality) > air <- airquality[(!is.na(airquality$Temp) & + !is.na(airquality$Ozone) & + !is.na(airquality$Solar.R)),] > # gives an error: > ## Not run: air.ip <- interp(air$Temp,air$Solar.R,air$Ozone) > # use mean of duplicate points: > air.ip <- interp(air$Temp,air$Solar.R,air$Ozone,duplicate="mean") > > > > cleanEx(); ..nameEx <- "interpp" > > ### * interpp > > flush(stderr()); flush(stdout()) > > ### Name: interpp > ### Title: Pointwise Bivariate Interpolation for Irregular Data > ### Aliases: interpp interpp.old interpp.new > ### Keywords: dplot > > ### ** Examples > > data(akima) > # linear interpolation at points (1,2), (5,6) and (10,12) > akima.lip<-interpp(akima$x, akima$y, akima$z,c(1,5,10),c(2,6,12)) > > > > ### *