# 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)
# compute absolute territorial deviation
com$tdevabs <- tdev(x = com, var1 = "INC", var2 = "TH", key = "EPT",
type = "abs")
# compute relative territorial deviation
com$tdevrel <- tdev(x = com, var1 = "INC", var2 = "TH", key = "EPT",
type = "rel")
if(require(mapsf)){
# relative deviation map
# set breaks
bks <- c(min(com$tdevrel), 80, 91, 100, 110, 125, max(com$tdevrel))
# plot a choropleth map of the relative territorial deviation
mf_map(x = com, var = "tdevrel", type = "choro", leg_pos = "topleft",
leg_title = "Relative Deviation\n(100 = general average)",
breaks = bks, border = NA,
pal = c("#4575B4", "#91BFDB", "#E0F3F8", "#FEE090", "#FC8D59", "#D73027"))
# add EPT boundaries
mf_map(x = ept, col = NA, add = TRUE)
# layout
mf_layout(title = "Territorial Deviation (reference: EPT of belonging)",
credits = paste0("Sources: GEOFLA® 2015 v2.1, Apur, impots.gouv.fr",
"\nMTA", packageVersion("MTA")),
arrow = FALSE)
# absolute deviation map
com$sign <- ifelse(test = com$tdevabs < 0, yes = "Under-Income", no = "Over-Income")
mf_map(ept)
mf_map(x = com, var = c("tdevabs", "sign"), type = "prop_typo", inches = 0.2,
leg_title = c("Absolute Deviation\n(Income redistribution, euros)",
"Redistribution direction"),
leg_pos = c("topleft", "topright"), leg_val_rnd = -2,
val_order = c("Under-Income", "Over-Income"),
pal = c("#ff0000","#0000ff"), add = TRUE)
# layout
mf_layout(title = "Territorial Deviation (reference: EPT of belonging)",
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