Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Forked from halhen/europe.R
Last active December 1, 2017 23:05
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cpsievert/7dd28a478b4c051180d802321353259d to your computer and use it in GitHub Desktop.
Save cpsievert/7dd28a478b4c051180d802321353259d to your computer and use it in GitHub Desktop.
library(tidyverse)
library(plotly)
# I'm being lazy, please don't do this
# setwd("~/Downloads/Version 2_0_1/")
d <- read_csv('GEOSTAT_grid_POP_1K_2011_V2_0_1.csv') %>%
rbind(read_csv('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 = T)) %>%
ungroup() %>%
tidyr::complete(lat, lng)
sd <- crosstalk::SharedData$new(d, ~lat)
p <- ggplot(sd, aes(lng, lat + 5*(value / max(value, na.rm = T)))) +
geom_line(
aes(group = lat, text = paste("Population:", value)),
size = 0.4, alpha = 0.8, color = '#5A3E37', na.rm = T
) +
coord_equal(0.9) +
ggthemes::theme_map()
ggplotly(p, tooltip = "text") %>%
highlight(persistent = TRUE, opacityDim = 0.5)
@cpsievert
Copy link
Author

cpsievert commented Apr 26, 2017

map2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment