-
-
Save kanishkamisra/134e2f35ad96d8dd59d18c41d5c8e61c 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 | |
) + | |
ggthemes::theme_map() | |
# support for coord_equal() coming soon! For now, you can do this... | |
ggplotly(p, tooltip = "text") %>% | |
highlight(persistent = TRUE, opacityDim = 0.5) %>% | |
layout(xaxis = list(scaleanchor = "y", scaleratio = 0.9)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment