Skip to contents

Stratify metric raster using metric quantiles.

Usage

strat_quantiles(
  mraster,
  mraster2 = NULL,
  nStrata,
  nStrata2 = NULL,
  plot = FALSE,
  details = FALSE,
  samp = 0.2,
  filename = NULL,
  overwrite = FALSE
)

Arguments

mraster

spatRaster. ALS metrics raster.

mraster2

Spatraster. Secondary covariate raster to stratify.

nStrata

Numeric. Number of quantiles to stratify mraster.

nStrata2

Numeric. Number of quantiles to stratify mraster2.

plot

Logical. Plots output strata raster and visualized strata with boundary dividers.

details

Logical. If FALSE (default) output is only stratification raster. If TRUE return a list where $details is additional stratification information and $raster is the output stratification spatRaster.

samp

Numeric. Determines proportion of cells to plot in scatterplot (default = 0.2). Lower values reduce visualization time.

filename

Character. Path to write stratified raster to disc.

overwrite

Logical. Specify whether filename should be overwritten on disc.

Value

Returns an output stratification spatRaster or a list when details = TRUE.

When a list is returned:

  1. details generates is a strata lookUp table for the stratification.

  2. raster is a stratified spatRaster based on quantiles

  3. plot is a ggplot histogram / scatter plot object (depends on whether metric2 was supplied). Histogram shows distribution and break points while scatter plot shows colour coded and strata boundaries.

See also

Other stratify functions: strat_breaks(), strat_kmeans(), strat_map(), strat_poly()

Author

Tristan R.H. Goodbody

Examples

#--- Load raster and existing plots---#
r <- system.file("extdata", "mraster.tif", package = "sgsR")
mr <- terra::rast(r)

strat_quantiles(
  mraster = mr$zq90,
  nStrata = 4,
  plot = TRUE
)

#> class       : SpatRaster 
#> dimensions  : 277, 373, 1  (nrow, ncol, nlyr)
#> resolution  : 20, 20  (x, y)
#> extent      : 431100, 438560, 5337700, 5343240  (xmin, xmax, ymin, ymax)
#> coord. ref. : UTM Zone 17, Northern Hemisphere 
#> source      : memory 
#> name        : strata 
#> min value   :      1 
#> max value   :      4 

strat_quantiles(
  mraster = mr$zq90,
  mraster2 = mr$zsd,
  nStrata = 3,
  nStrata2 = 4
)
#> class       : SpatRaster 
#> dimensions  : 277, 373, 1  (nrow, ncol, nlyr)
#> resolution  : 20, 20  (x, y)
#> extent      : 431100, 438560, 5337700, 5343240  (xmin, xmax, ymin, ymax)
#> coord. ref. : UTM Zone 17, Northern Hemisphere 
#> source      : memory 
#> name        : strata 
#> min value   :      1 
#> max value   :     12