# Load data
library(sf)
com <- st_read(system.file("metroparis.gpkg", package = "MTA"), layer = "com", quiet = TRUE)
ept <- st_read(system.file("metroparis.gpkg", package = "MTA"), layer = "ept", quiet = TRUE)
# Prerequisites - Compute the 3 deviations
com$gdev <- gdev(x = com, var1 = "INC", var2 = "TH")
com$tdev <- tdev(x = com, var1 = "INC", var2 = "TH", key = "EPT")
com$sdev <- sdev(x = com, var1 = "INC", var2 = "TH", order = 1)
#Example 1 - Wealthiest territorial units
# Compute map_mst
mst <- map_mst(x = com, gdevrel = "gdev", tdevrel = "tdev", sdevrel = "sdev",
threshold = 125, superior = TRUE)
# Unlist outputs of the function
com <- mst$geom
cols <- mst$cols
leg_val <- mst$leg_val
if(require(mapsf)){
# Cartography
mf_map(x = com, var = "mst", type = "typo", border = "white", lwd = 0.2,
pal = cols, val_order = unique(com$mst), leg_pos = NA)
mf_map(ept, col = NA, border = "black", lwd = 1, add = TRUE)
mf_legend(type = "typo", val = leg_val, pal = cols,
title = "Situation on General (G)\nTerrorial (T) and\nSpatial (S) contexts",
pos = "topleft")
mf_label(x = com[com$mst == 7,], var = "LIBCOM",
cex = 0.6, halo = TRUE, overlap = FALSE)
mf_layout(title = "3-Deviations synthesis : Territorial units above index 125",
credits = paste0("Sources: GEOFLA® 2015 v2.1, Apur, impots.gouv.fr",
"\nMTA", packageVersion("MTA")),
arrow = FALSE)
}
# Example 2 - Lagging territorial units
# Compute map_mst
mst <- map_mst(x = com, gdevrel = "gdev", tdevrel = "tdev", sdevrel = "sdev",
threshold = 75, superior = FALSE)
# Unlist resulting function
com <- mst$geom
cols <- mst$cols
leg_val <- mst$leg_val
if(require(mapsf)){
# Cartography
mf_map(x = com, var = "mst", type = "typo", border = "white", lwd = 0.2,
pal = cols, val_order = unique(com$mst), leg_pos = NA)
mf_map(ept, col = NA, border = "black", lwd = 1, add = TRUE)
mf_legend(type = "typo", val = leg_val, pal = cols,
title = "Situation on General (G)\nTerrorial (T) and\nSpatial (S) contexts",
pos = "topleft")
mf_label(x = com[com$mst == 7,], var = "LIBCOM",
cex = 0.6, halo = TRUE, overlap = FALSE)
mf_layout(title = "3-Deviations synthesis : Territorial units below index 75",
credits = paste0("Sources: GEOFLA® 2015 v2.1, Apur, impots.gouv.fr",
"\nMTA", packageVersion("MTA")),
arrow = FALSE)
}
Run the code above in your browser using DataLab