# NOT RUN {
library(sf)
library(cartography)
# load data
data("GrandParisMetropole")
# compute absolute spatial deviation in a neighborhood defined by a contiguity
# order of 2.
com$sdevabs <- sdev(x = com, var1 = "INC", var2 = "TH", order =2, 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)
# map deviations
# set graphical parameters
par(mar = c(0,0,1.2,0))
# set breaks
bks <- c(min(com$scardevrel),75,100,125,150,max(com$scardevrel))
# set colot palette
cols <- carto.pal(pal1 = "blue.pal", n1 = 2,
pal2 = "wine.pal", n2 = 3)
# plot a choropleth map of the relative spatial deviation
choroLayer(x = com, var = "scardevrel",
legend.pos = "topleft",
legend.title.txt = "Relative Deviation\n(100 = spatial average)",
breaks = bks, border = NA,
col = cols)
# add symbols proportional to the absolute spatial deviation
com$sign <- ifelse(test = com$scardevabs<0, yes = "negative", no = "positive")
propSymbolsTypoLayer(x = com, var = "scardevabs",var2 = "sign",
legend.var.pos = "left",legend.values.rnd = -2,
legend.var2.values.order = c("positive", "negative"),
legend.var.title.txt = "Absolute Deviation\n(Income redistribution)",
col = c("#ff000050","#0000ff50"),legend.var2.pos = "n",
legend.var.style = "e", inches = 0.2)
# add EPT boundaries
plot(st_geometry(ept), add=TRUE)
# add a layout
layoutLayer(title = "Spatial Deviation (neighborhood : 10 minutes by car)",
sources = "GEOFLA<U+00AE> 2015 v2.1, Apur, impots.gouv.fr",
north = TRUE, scale = 5, tabtitle = TRUE, frame = FALSE, theme = "red.pal",
author = "MTA")
# }
Run the code above in your browser using DataLab