If you are familiar with this famous Joy Division cover, you might remember that last year we shared a link that shows you how to reproduce the cover using R ggplot2. If you are a big fan of Joy Division and R, you should know that there is an R package just for that (by @mikefc).
About three years ago in 2014, James Cheshire created the Population Lines Print, a stylized map using lines to show population density in the world. It uses roughly the same data visualization style used in the Joy Division cover.
credit: James Cheshire
How can you create a nice-looking map like this? Ask no more. James has recently shared the R script and a bit of the history behind his map. Henrik Lindberg has also generously written a gist with a simple and reproducible code to create a map with the same style showing the distribution of the population density in Europe, using R and ggplot2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat | |
# Originally seen at http://spatial.ly/2014/08/population-lines/ | |
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess, | |
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after | |
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line. | |
# The result of the code below can be seen at http://imgur.com/ob8c8ph | |
library(tidyverse) | |
read_csv('../data/geostat-2011/GEOSTAT_grid_POP_1K_2011_V2_0_1.csv') %>% | |
rbind(read_csv('../data/geostat-2011/JRC-GHSL_AIT-grid-POP_1K_2011.csv') %>% | |
mutate(TOT_P_CON_DT='')) %>% | |
mutate(lat = as.numeric(gsub('.*N([0-9]+)[EW].*', '\\1', GRD_ID))/100, | |
lng = as.numeric(gsub('.*[EW]([0-9]+)', '\\1', GRD_ID)) * ifelse(gsub('.*([EW]).*', '\\1', GRD_ID) == 'W', -1, 1) / 100) %>% | |
filter(lng > 25, lng < 60) %>% | |
group_by(lat=round(lat, 1), lng=round(lng, 1)) %>% | |
summarize(value = sum(TOT_P, na.rm=TRUE)) %>% | |
ungroup() %>% | |
complete(lat, lng) %>% | |
ggplot(aes(lng, lat + 5*(value/max(value, na.rm=TRUE)))) + | |
geom_line(size=0.4, alpha=0.8, color='#5A3E37', aes(group=lat), na.rm=TRUE) + | |
ggthemes::theme_map() + | |
coord_equal(0.9) | |
ggsave('/tmp/europe.png', width=10, height=10) |
credit: Henrik Lindberg
I made @galka_max Europe map interactive with 2 more lines of #rstats code https://t.co/KZp0w5YoFH pic.twitter.com/a4GaFJRJVn— Carson Sievert (@cpsievert) 26 April 2017