set.seed(1014)
knitr::opts_chunk$set(
  echo = TRUE,
  comment = "#>",
  collapse = TRUE,
  cache = FALSE,
  out.width = "70%",
  fig.align = "center",
  fig.width = 6,
  fig.asp = 0.618,
  fig.show = "hold"
)

This article shows how to krig soil data with the function krig() developed by Graham Zemunik (see ?krig()).

library(ggplot2)
library(purrr)
library(fgeo.tool)
library(fgeo.krig)
soil <- fgeo.krig::soil_random
str(soil)

Compare parameters

Krige with automated parameters.

auto <- krig(soil, var = "m3al", quiet = TRUE)
summary(auto)
as_tibble(auto)

Try also:

View(auto)

With custom parameters (arbitrary but based on automated kriging parameters).

params <- list(
  model = "circular", range = 100, nugget = 1000, sill = 46000, kappa = 0.5
)
custom <- krig(soil, var = "m3al", params = params, quiet = TRUE)

Compare.

title_auto <- "Automated parameters"
ggplot(as_tibble(auto), aes(x = x, y = y, fill = z)) +
  geom_tile() + 
  coord_equal() +
  labs(title = title_auto)

title_custom <- "Custom parameters"
ggplot(as_tibble(custom), aes(x = x, y = y, fill = z)) +
  geom_tile() + 
  coord_equal() +
  labs(title = title_custom)

Iterate over multiple soil variables

soil <- fgeo.krig::soil_fake
soil

Scale soil data to make their values fall within the same range. This is not crucial, but it will ease visual comparison.

soil_vars <- c("mg", "c", "p")
soil_scaled <- modify_at(soil_fake, .at = soil_vars, scale)

krig_list <- krig(soil_scaled, soil_vars, quiet = TRUE)

summary(krig_list)

Transform krig results to a tibble for easier manipulation and visualization.

# as.data.frame(krig_list) also works but is hader to visualize
(krig_df <- as_tibble(krig_list))

tail(krig_df)

Visualize multiple soil variables

The structure of this dataframe allows faceting with gglot2.

ggplot(krig_df, aes(x, y, fill = z)) +
  geom_tile() +
  facet_wrap("var") +
  coord_equal()


forestgeo/fgeo.krig documentation built on June 26, 2019, 8:09 p.m.