Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

cross.tab

Class comparison between two nominal rasters


Description

Creates a labeled cross tabulation between two nominal rasters

Usage

cross.tab(x, y, values = NULL, labs = NULL, pct = FALSE, ...)

Arguments

x

rasterLayer class object

y

rasterLayer class object to compare to x

values

Expected values in both rasters

labs

Labels associated with values argument

pct

(TRUE/FALSE) return proportions rather than counts

...

Additional arguments

Value

a table with the cross tabulated counts

Note

This function returns a cross tabulation between two nominal rasters. Arguments allow for labeling the results and returning proportions rather than counts. It also accounts for asymmetrical classes between the two rasters

Author(s)

Jeffrey S. Evans <jeffrey_evans@tnc.org>

References

Pontius Jr, R.G., Shusas, E., McEachern, M. (2004). Detecting important categorical land changes while accounting for persistence. Agriculture, Ecosystems & Environment 101(2):251-268.

See Also

raster::crosstab

Examples

library(sp)
 library(raster)
   data(meuse.grid)
 
 r1 <- sp::SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")], 
                                  data = meuse.grid)
 lulc2010 <- raster(r1)
   na.idx <- which(!is.na(lulc2010[]))
     lulc2010[na.idx] <- sample(1:5, length(na.idx), replace=TRUE)
  
 lulc2020 <- raster(lulc2010)
   lulc2020[na.idx] <- sample(1:5, length(na.idx), replace=TRUE)
 
 ( v = sort(unique(c(lulc2010[], lulc2020[]))) )
 l = c("water","urban","forest",
       "ag","barren")

 cross.tab(lulc2010, lulc2020) 
 cross.tab(lulc2010, lulc2020, values = v, labs = l)
 cross.tab(lulc2010, lulc2020, values = v, labs = l, pct=TRUE)

# Create asymmetrical classes 
lulc2020[na.idx] <- sample(c(1,2,4,5), length(na.idx), replace=TRUE)

cross.tab(lulc2010, lulc2020, values = v, labs = l, pct=TRUE)

spatialEco

Spatial Analysis and Modelling Utilities

v1.3-6
GPL-3
Authors
Jeffrey S. Evans [aut, cre], Melanie A. Murphy [ctb], Karthik Ram [ctb]
Initial release
2021-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.