Skip to contents

This function calls similar_soils() iteratively to estimate the proportions of observations corresponding to distinct groups of similar soils. Use it exhaustively group all observations (for example, within a map unit or other conceptual unit of interest)

Usage

design_mapunit(
  x,
  mapping,
  idname = "id",
  component_labels = SOILmilaR::greekletters[[1]],
  ...
)

Arguments

x

A data.frame or a SoilProfileCollection.

mapping

A named list of rating functions.

idname

The name of the ID column in x. Default: "id".

component_labels

A character vector of labels to assign to components. Default: greekletters[[1]]

...

Additional arguments passed on to similar_soils(), such as threshold_single or threshold_all.

Value

A data.frame containing the original data along with a new 'compname' column that assigns a map unit component label to each group of similar soils.

Details

This function automates the iterative process of calling similar_soils() to build out an estimate of map unit composition.

As a special case, if threshold_single and threshold_all are set to 0, the function will use a more efficient method. It will directly group all soils that share the exact same combination of rated properties, as this is the logical outcome of a zero-distance threshold. The component labels are assigned based on the size of the groups, with the largest group being assigned the first label.

Examples


data("loamy", package = "SOILmilaR")

rate_taxpartsize <- function(x) {
  dplyr::case_match(x,
                    c("sandy-skeletal") ~ 1,
                    c("sandy") ~ 3,
                    c("loamy", "coarse-loamy", "coarse-silty") ~ 5,
                    c("fine-loamy", "fine-silty") ~ 7,
                    c("clayey", "fine") ~ 9,
                    c("very-fine") ~ 11,
                    c("loamy-skeletal", "clayey-skeletal") ~ 13,
                    "fragmental" ~ 15)
}

rate_depthclass <- function(x,
                            breaks = c(
                              `very shallow` = 25,
                              `shallow` = 50,
                              `moderately deep` = 100,
                              `deep` = 150,
                              `very deep` = 1e4
                            ),
                            ...) {
  res <- cut(x, c(0, breaks))
  factor(res, levels = levels(res), labels = names(breaks))
}

m <- list(taxpartsize = rate_taxpartsize, depth = rate_depthclass)

mapunit_composition <- design_mapunit(loamy, m)

mapunit_composition[order(mapunit_composition$component), ]
#>    id    taxpartsize     depth component
#> 1  A1     fine-loamy  68.07141     Alpha
#> 2  B1     fine-loamy 125.65509     Alpha
#> 3  C1     fine-loamy  82.03235     Alpha
#> 4  D1     fine-loamy 136.54700     Alpha
#> 11 A2     fine-loamy 145.74779     Alpha
#> 12 B2     fine-loamy 138.76439     Alpha
#> 13 C2     fine-loamy 114.43111     Alpha
#> 14 D2     fine-loamy 126.47875     Alpha
#> 21 A3     fine-loamy 111.48825     Alpha
#> 23 C3     fine-loamy  79.15651     Alpha
#> 24 D3     fine-loamy  66.55412     Alpha
#> 8  H1 loamy-skeletal 137.62819      Beta
#> 9  I1 loamy-skeletal  98.41503      Beta
#> 10 J1 loamy-skeletal  87.51069      Beta
#> 18 H2 loamy-skeletal  59.88691      Beta
#> 20 J2 loamy-skeletal  61.63697      Beta
#> 28 H3 loamy-skeletal 128.42479      Beta
#> 30 J3 loamy-skeletal  85.58064      Beta
#> 6  F1          loamy  40.23900     Delta
#> 15 E2          loamy  37.83057     Delta
#> 22 B3          loamy  45.90668     Delta
#> 19 I2     fragmental  71.59082   Epsilon
#> 29 I3     fragmental 126.34937   Epsilon
#> 5  E1   coarse-loamy 143.15374     Gamma
#> 7  G1   coarse-loamy  95.73213     Gamma
#> 16 F2   coarse-loamy  89.94654     Gamma
#> 17 G2   coarse-loamy 122.22285     Gamma
#> 25 E3   coarse-loamy 128.68360     Gamma
#> 26 F3   coarse-loamy  86.57938     Gamma
#> 27 G3   coarse-loamy 128.15740     Gamma

sort(prop.table(table(mapunit_composition$component)), decreasing = TRUE)
#> 
#>      Alpha       Beta      Gamma      Delta    Epsilon 
#> 0.36666667 0.23333333 0.23333333 0.10000000 0.06666667