-
-
Save cpsievert/7dd28a478b4c051180d802321353259d to your computer and use it in GitHub Desktop.
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
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) |
Author
cpsievert
commented
Apr 26, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment