# 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)
cardist <- read.table(system.file("cardist.txt", package = "MTA"), check.names = FALSE)
cardist <- as.matrix(cardist)
# compute absolute spatial deviation in a neighborhood defined by a contiguity
# order of 1.
com$sdevabs <- sdev(x = com, var1 = "INC", var2 = "TH", order = 1, type = "abs")
#compute relative spatial deviation in a neighborhood defined within a distance
# of 5km between communes' centroids
com$sdevrel <- sdev(x = com, var1 = "INC", var2 = "TH", type = "rel", dist = 5000)
# compute absolute spatial deviation in a neighborhood defined within a road
# travel time of 10 minutes by car
com$scardevabs <- sdev(x = com, var1 = "INC", var2 = "TH", type = "abs", dist = 10, mat = cardist)
# compute relative spatial deviation in a neighborhood defined within a road
# travel time of 10 minutes by car
com$scardevrel <- sdev(x = com, var1 = "INC", var2 = "TH", type = "rel", dist = 10, mat = cardist)
if(require(mapsf)){
# relative deviation map
# set breaks
bks <- c(min(com$scardevrel), 75, 100, 125, 150, max(com$scardevrel))
# plot a choropleth map of the relative spatial deviation
mf_map(x = com, var = "scardevrel", type = "choro", leg_pos = "topleft",
leg_title = "Relative Deviation\n(100 = spatial average)",
breaks = bks, border = NA,
pal = c("#91BFDB", "#E0F3F8", "#FEE090", "#FC8D59", "#D73027"))
# add EPT boundaries
mf_map(x = ept, col = NA, add = TRUE)
# layout
mf_layout(title = "Spatial Deviation (neighborhood : 10 minutes by car)",
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