-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
## ---- fig.width=5, fig.height=5------------------------------------------ | ||
library(SpatialPosition) | ||
data(spatData) | ||
|
||
# Compute potentials (accessibility) | ||
globalAccessibility <- stewart(knownpts = spatPts, varname = "Capacite", | ||
typefct = "exponential", span = 1000, beta = 3, | ||
resolution = 50, | ||
mask = spatMask) | ||
|
||
# Create a raster | ||
rasterAccessibility <- rasterStewart(x = globalAccessibility, mask = spatMask) | ||
|
||
# Plot the raster | ||
par(mar = c(4,2,2,1)) | ||
|
||
plotStewart(x = rasterAccessibility, add = FALSE, nclass = 6) | ||
|
||
# The function returns break values | ||
breakValues <- plotStewart(x = rasterAccessibility, add = FALSE, nclass = 6) | ||
|
||
# Create contour lines and add them to the plot | ||
contLines <- rasterToContour(x = rasterAccessibility, levels = breakValues) | ||
plot(contLines, add = TRUE) | ||
plot(spatMask, add = TRUE) | ||
|
||
mtext("Global Accessibility to Public Hospitals", side = 3,cex = 1.5) | ||
mtext(text = "Potential nb. of beds | ||
distance function: exponential, span = 1 km, beta = 3", | ||
side = 1, line = 1) | ||
|
||
|
||
|
||
## ---- fig.width=5, fig.height=5------------------------------------------ | ||
row.names(spatPts) | ||
catchReilly <- reilly(knownpts = spatPts, varname = "Capacite", | ||
typefct = "exponential", span = 750, beta = 2, | ||
resolution = 50, mask = spatMask) | ||
|
||
# Create a raster | ||
rasterCatch <- rasterReilly(x = catchReilly, mask = spatMask) | ||
|
||
par(mar = c(4,2,2,1)) | ||
# Plot the raster and add the points | ||
plotReilly(x = rasterCatch) | ||
plot(spatPts, pch = 20, add = TRUE) | ||
|
||
mtext("Catchment Areas of Public Hospitals", side = 3,cex = 1.5) | ||
mtext(text = "distance function: exponential, span = 0.75 km, beta = 2", | ||
side = 1, line = 0) | ||
|
||
## ---- fig.width=5, fig.height=5------------------------------------------ | ||
### | ||
catchHuff <- huff(knownpts = spatPts, varname = "Capacite", | ||
typefct = "exponential", span = 750, beta = 2, | ||
resolution = 50, mask = spatMask) | ||
|
||
# Create a raster | ||
rasterCatch <- rasterHuff(x = catchHuff, mask = spatMask) | ||
|
||
# Plot the raster and add the points | ||
par(mar = c(4,2,2,1)) | ||
plotHuff(x = rasterCatch) | ||
plot(spatPts, pch = 20, col = "red", add = TRUE) | ||
|
||
mtext("Probabilistic Catchment Areas \nof Public Hospitals", | ||
side = 3,cex = 1.5, line=-1.5) | ||
mtext(text = "distance function: exponential, span = 0.75 km, beta = 2", | ||
side = 1, line = 0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
## ----regionalmap, fig.width=7, fig.height=6------------------------------ | ||
library(cartography) | ||
library(SpatialPosition) | ||
data(nuts2006) | ||
|
||
# Compute the GDP per capita variable | ||
nuts3.df$gdpcap <- nuts3.df$gdppps2008 * 1000000 / nuts3.df$pop2008 | ||
|
||
# Discretize of the variable | ||
bv <- quantile(nuts3.df$gdpcap, seq(from = 0, to = 1, length.out = 9)) | ||
|
||
# Draw the map | ||
opar <- par(mar = c(0,0,1.2,0)) | ||
|
||
# Set a color palette | ||
pal <- carto.pal(pal1 = "wine.pal", n1 = 8) | ||
|
||
# Draw the basemap | ||
plot(nuts0.spdf, add = F, border = NA, bg = "#cdd2d4") | ||
plot(world.spdf, col = "#f5f5f3ff", border = "#a9b3b4ff", add = TRUE) | ||
|
||
# Map the regional GDP per capita | ||
choroLayer(spdf = nuts3.spdf, df = nuts3.df, | ||
var = "gdpcap", | ||
legend.pos = "topright", | ||
breaks = bv, col = pal, | ||
border = NA, | ||
legend.title.txt = "GDP per capita", | ||
legend.values.rnd = -2, | ||
add = TRUE) | ||
plot(nuts0.spdf, add = TRUE, lwd = 0.5, border = "grey30") | ||
plot(world.spdf, col = NA, border = "#7DA9B8", add = TRUE) | ||
|
||
# Set a layout | ||
layoutLayer(title = "Wealth Inequality in Europe", | ||
sources = "Basemap: UMS RIATE, 2015 - Data: Eurostat, 2008", | ||
author = "T. Giraud, 2015") | ||
par(opar) | ||
|
||
## ----regionalmappot, fig.width=7, fig.height=6--------------------------- | ||
# Create a distance matrix between units | ||
mat <- CreateDistMatrix(knownpts = nuts3.spdf, | ||
unknownpts = nuts3.spdf) | ||
|
||
# Merge the data frame and the SpatialPolygonsDataFrame | ||
nuts3.spdf@data <- nuts3.df[match(nuts3.spdf$id, nuts3.df$id),] | ||
|
||
# Compute the potentials of population per units | ||
# function = exponential, beta = 2, span = 75 km | ||
poppot <- stewart(knownpts = nuts3.spdf, | ||
unknownpts = nuts3.spdf, | ||
matdist = mat, | ||
varname = "pop2008", | ||
typefct = "exponential", | ||
beta = 2, | ||
span = 75000) | ||
|
||
# Compute the potentials of GDP per units | ||
# function = exponential, beta = 2, span = 75 km | ||
gdppot <- stewart(knownpts = nuts3.spdf, | ||
unknownpts = nuts3.spdf, | ||
matdist = mat, | ||
varname = "gdppps2008", | ||
typefct = "exponential", | ||
beta = 2, | ||
span = 75000) | ||
|
||
# Create a data frame of potential GDP per capita | ||
pot <- data.frame(id = nuts3.df$id, | ||
gdpcap = gdppot$OUTPUT * 1000000 / poppot$OUTPUT, | ||
stringsAsFactors = FALSE) | ||
|
||
# Draw the map | ||
par <- par(mar = c(0,0,1.2,0)) | ||
|
||
# Draw the basemap | ||
plot(nuts0.spdf, add = F, border = NA, bg = "#cdd2d4") | ||
plot(world.spdf, col = "#f5f5f3ff", border = "#a9b3b4ff", add = TRUE) | ||
|
||
# Map the regional potential of GDP per capita | ||
choroLayer(spdf = nuts3.spdf, df = pot, | ||
var = "gdpcap", | ||
legend.pos = "topright", | ||
breaks = bv, col = pal, | ||
border = NA, | ||
legend.title.txt = "Potential\nGDP per capita", | ||
legend.values.rnd = -2, add = TRUE) | ||
plot(nuts0.spdf, add=T, lwd = 0.5, border = "grey30") | ||
plot(world.spdf, col = NA, border = "#7DA9B8", add=T) | ||
|
||
# Set a text to explicit the function parameters | ||
text(x = 6271272, y = 3743765, | ||
labels = "Distance function:\n- type = exponential\n- beta = 2\n- span = 75 km", | ||
cex = 0.8, adj = 0, font = 3) | ||
|
||
# Set a layout | ||
layoutLayer(title = "Wealth Inequality in Europe", | ||
sources = "Basemap: UMS RIATE, 2015 - Data: Eurostat, 2008", | ||
author = "T. Giraud, 2015") | ||
par(opar) | ||
|
||
## ----smoothedmappot, fig.width=7, fig.height=6--------------------------- | ||
# Compute the potentials of population on a regular grid (50km span) | ||
# function = exponential, beta = 2, span = 75 km | ||
poppot <- stewart(knownpts = nuts3.spdf, | ||
varname = "pop2008", | ||
typefct = "exponential", | ||
span = 75000, | ||
beta = 2, | ||
resolution = 50000, | ||
mask = nuts0.spdf) | ||
|
||
# Compute the potentials of GDP on a regular grid (50km span) | ||
# function = exponential, beta = 2, span = 75 km | ||
gdppot <- stewart(knownpts = nuts3.spdf, | ||
varname = "gdppps2008", | ||
typefct = "exponential", | ||
span = 75000, | ||
beta = 2, | ||
resolution = 50000, | ||
mask = nuts0.spdf) | ||
|
||
# Transform the regularly spaced SpatialPointsDataFrame to a raster | ||
popras <- rasterStewart(poppot) | ||
gdpras <- rasterStewart(gdppot) | ||
|
||
# Compute the GDP per capita | ||
ras <- gdpras * 1000000 / popras | ||
|
||
# Create a SpatialPolygonsDataFrame from the raster | ||
pot.spdf <- rasterToContourPoly(r = ras, | ||
breaks = bv, | ||
mask = nuts0.spdf) | ||
|
||
# Draw the map | ||
par <- par(mar = c(0,0,1.2,0)) | ||
|
||
# Draw the basemap | ||
plot(nuts0.spdf, add = F, border = NA, bg = "#cdd2d4") | ||
plot(world.spdf, col = "#f5f5f3ff", border = "#a9b3b4ff", add = TRUE) | ||
|
||
# Map the potential GDP per Capita | ||
choroLayer(spdf = pot.spdf, df = pot.spdf@data, var = "center", | ||
legend.pos = "topright", | ||
breaks = bv, col = pal, add=T, | ||
border = "grey90", lwd = 0.2, | ||
legend.title.txt = "Potential\nGDP per capita", | ||
legend.values.rnd = -2) | ||
plot(nuts0.spdf, add=T, lwd = 0.5, border = "grey30") | ||
plot(world.spdf, col = NA, border = "#7DA9B8", add=T) | ||
|
||
# Set a text to explicit the function parameters | ||
text(x = 6271272, y = 3743765, | ||
labels = "Distance function:\n- type = exponential\n- beta = 2\n- span = 75 km", | ||
cex = 0.8, adj = 0, font = 3) | ||
|
||
# Set a layout | ||
layoutLayer(title = "Wealth Inequality in Europe", | ||
sources = "Basemap: UMS RIATE, 2015 - Data: Eurostat, 2008", | ||
author = "T. Giraud, 2015") | ||
par(opar) | ||
|