Create a gist now

Instantly share code, notes, and snippets.

@cpsievert /europe.R forked from halhen/europe.R
Last active Dec 1, 2017

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@cpsievert

cpsievert Apr 26, 2017

map2

Owner

cpsievert commented Apr 26, 2017

map2

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