Automatic spatial interpolation with R: the automap package

February 17, 2013

(This article was first published on NumberTheory » R stuff, and kindly contributed to R-bloggers)

In case of continuously collected data, e.g. observations from a monitoring network, spatial interpolation of this data cannot be done manually. Instead, the interpolation should be done automatically. To achieve this goal, I developed the automap package. automap builds on top of the excellent gstat package, and provides automatic spatial interpolation, more specifically, automatic kriging. Kriging in its more simple form (Ordinary Kriging, Universal Kriging, aka Kriging with External Drift) is actually nothing more than linear regression with spatially correlated residuals.

automap provides the following set of functions (for details I refer to the online manual):

  • autofitVariogram, automatically fits the variogram model to the data.
  • autoKrige, automatically fits the variogram model using autofitVariogram, and creates an interpolated map.
  •, automatically fits the variogram model using autofitVariogram, and performs cross-validation. Uses under the hood.
  •, allows comparison of the output of and This can be used to evaluate the performance of different interpolation algorithms. allows comparison using both summary statistics and spatial plots.

In general, the interface of automap mimics that of gstat. The following code snippets show some examples of creating interpolated maps using automap:

# Ordinary kriging
kriging_result = autoKrige(zinc~1, meuse, meuse.grid)
# Universal kriging
kriging_result = autoKrige(zinc~soil+ffreq+dist, meuse, meuse.grid)

You can get automap from either CRAN:


or my bitbucket account.

hg clone

PS: automap was the first package I wrote, at the beginning of my PhD, so it is not the most beautiful code I ever wrote ;) .

To leave a comment for the author, please follow the link and comment on their blog: NumberTheory » R stuff. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)