Skip to content

Instantly share code, notes, and snippets.

@danimad
Forked from halhen/europe.R
Created April 23, 2017 19:52
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 danimad/9fd9593c9745ce71a0f1825e80596923 to your computer and use it in GitHub Desktop.
Save danimad/9fd9593c9745ce71a0f1825e80596923 to your computer and use it in GitHub Desktop.
# 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/
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(lng=round(lng, 1), lat=round(lat, 1)) %>%
summarize(value = sum(TOT_P, na.rm=TRUE)) %>%
ungroup() %>%
group_by(lat) %>%
arrange(lng) %>%
mutate(next.value = lead(value)) %>%
ggplot(aes(lng, lat + 5*(value/max(value)), xend=lng+0.1, yend=lat + 5*(next.value/max(value)))) +
geom_segment(size=0.4, alpha=0.8, color='#5A3E37') +
ggthemes::theme_map() +
coord_equal(0.9)
ggsave('/tmp/europe.png', width=10, height=10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment