Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@briatte
Forked from rCarto/disc2019.R
Created July 10, 2019 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briatte/40d37c2543072bc948b736aad9414bb9 to your computer and use it in GitHub Desktop.
Save briatte/40d37c2543072bc948b736aad9414bb9 to your computer and use it in GitHub Desktop.
library(cartography)
library(sp)
# Load data
data(nuts2006)
# Get a SpatialLinesDataFrame of countries borders
nuts0.contig.spdf <- getBorders(nuts0.spdf)
# Get the GDP per capita
nuts0.df$gdpcap <- nuts0.df$gdppps2008/nuts0.df$pop2008*1000000
png("disc.png", width = 1050, height = 750, res = 140)
# set margins
par(mar = c(0,0,1.2,0))
# Plot a layer with the extent of the EU28 countries with only a background color
plot(nuts0.spdf, border = NA, col = NA, bg = "#A6CAE0")
# Plot non european space
plot(world.spdf, col = "#E3DEBF", border=NA, add=TRUE)
# Plot GDP per capita with a choropleth layer
choroLayer(spdf = nuts0.spdf, df = nuts0.df, var = "gdpcap", border = "grey80",
col = carto.pal(pal1 = "kaki.pal", n1 = 6), method = "quantile",
nclass = 6, add=TRUE, legend.pos = "right",
legend.values.rnd = -2,
legend.title.txt = "GDP per Capita\n(in euros)")
# Plot discontinuities
discLayer(x = nuts0.contig.spdf, # SpatialLinesDataFrame of borders
df = nuts0.df, # data frame on countries
var = "gdpcap", # variable used to compute discontinuties
type = "rel", # type of discontinuity measure
method="equal", # discretisation of discontinuities
nclass=4, # number of discontinuities classes
threshold = 0.5, # representation threshold of discontinuities
sizemin = 0.5, # minimum size of discontinuities lines
sizemax = 6, # maximum size of discontinuities lines
col="red", # color of the lines
legend.values.rnd = 1,
legend.title.txt = "Discontinuities in \nGDP per Capita\n(relative)",
legend.pos = "topright",
add=TRUE)
# Layout
layoutLayer(title = "Wealth Disparities in Europe", coltitle = "black",
sources = "Eurostat, 2011", scale = 200,
author = "cartography", frame ="", col = NA)
north(pos = "topleft")
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment