Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement