A short, self-contained tutorial for building experimental and fitted semivariograms in R using gstat and the built-in meuse dataset (no external files).
- Nugget, sill, range — what they mean and how to read them
- Empirical semivariogram computation
- Model fitting (exponential example)
- Directional variograms (anisotropy check)
Open the rendered HTML tutorial:
- https://parker-group.github.io/variogram_tutorial1/
variogram_tutorial.html(in this repo)
In R:
install.packages(c("gstat", "sp", "sf", "rmarkdown")) # first time
rmarkdown::render("variogram_tutorial1.rmd", output_format = "html_document")Click to launch an interactive RStudio session with Binder:
When RStudio opens in the browser:
- In the Files pane, click
variogram_tutorial1.rmd - Click Knit to render, or use Run ▶ to step through
If you want to quickly reproduce the example without opening the .Rmd file, copy/paste this into your R console:
# Install required packages (skip if already installed)
install.packages(c("gstat", "sp"))
# Load libraries
library(sp)
library(gstat)
# Load the example data
data(meuse)
coordinates(meuse) <- ~x+y
# Compute experimental variogram
v_exp <- variogram(log(zinc)~1, meuse)
plot(v_exp)
# Fit an exponential model
v_model <- fit.variogram(v_exp, model=vgm(psill=0.6, model="Exp", range=900, nugget=0.05))
plot(v_exp, v_model)This minimal example runs the core variogram workflow without needing any extra files.
Continue to Spatial Dependence Part 2
▶️ View the live tutorial here
- Binder setup files (
runtime.txtandinstall.R) are included for reproducibility. - First Binder launch may take 1–3 minutes while it builds the environment.