Creates a labeled cross tabulation between two nominal rasters

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

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

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org>

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[]))) )
#> [1] 1 2 3 4 5
l = c("water","urban","forest", "ag","barren") cross.tab(lulc2010, lulc2020)
#> lulc2010 #> lulc2020 1 2 3 4 5 #> 1 109 123 126 132 123 #> 2 123 129 136 110 117 #> 3 114 129 122 139 129 #> 4 125 124 117 129 118 #> 5 132 103 124 139 131
cross.tab(lulc2010, lulc2020, values = v, labs = l)
#> lulc2010 #> lulc2020 water urban forest ag barren #> water 109 123 126 132 123 #> urban 123 129 136 110 117 #> forest 114 129 122 139 129 #> ag 125 124 117 129 118 #> barren 132 103 124 139 131
cross.tab(lulc2010, lulc2020, values = v, labs = l, pct=TRUE)
#> lulc2010 #> lulc2020 water urban forest ag barren #> water 0.17781 0.20000 0.18009 0.20392 0.20986 #> urban 0.20065 0.20976 0.20379 0.20228 0.16375 #> forest 0.20555 0.22114 0.19273 0.19086 0.19714 #> ag 0.21533 0.17886 0.21959 0.21044 0.22099 #> barren 0.20065 0.19024 0.20379 0.19250 0.20827
# 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)
#> lulc2010 #> lulc2020 water urban forest ag barren #> water 0.26427 0.23252 0.25592 0.24144 0.26391 #> urban 0.28385 0.23902 0.27804 0.27080 0.24801 #> ag 0.23817 0.25203 0.22433 0.24959 0.24642 #> barren 0.21370 0.27642 0.24171 0.23817 0.24165