Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. library(tidyverse)
  2. library(plotly)
  3.  
  4. # I'm being lazy, please don't do this
  5. # setwd("~/Downloads/Version 2_0_1/")
  6.  
  7. d <- read_csv('GEOSTAT_grid_POP_1K_2011_V2_0_1.csv') %>%
  8. rbind(read_csv('JRC-GHSL_AIT-grid-POP_1K_2011.csv') %>%
  9. mutate(TOT_P_CON_DT = '')) %>%
  10. mutate(
  11. lat = as.numeric(gsub('.*N([0-9]+)[EW].*', '\\1', GRD_ID))/100,
  12. lng = as.numeric(gsub('.*[EW]([0-9]+)', '\\1', GRD_ID)) * ifelse(gsub('.*([EW]).*', '\\1', GRD_ID) == 'W', -1, 1) / 100
  13. ) %>%
  14. filter(lng > 25, lng < 60) %>%
  15. group_by(lat = round(lat, 1), lng = round(lng, 1)) %>%
  16. summarize(value = sum(TOT_P, na.rm = T)) %>%
  17. ungroup() %>%
  18. tidyr::complete(lat, lng)
  19.  
  20. p <- ggplot(d, aes(lng, lat + 5*(value / max(value, na.rm = T)))) +
  21. geom_line(
  22. aes(group = lat, text = paste("Population:", value)),
  23. size = 0.4, alpha = 0.8, color = '#5A3E37', na.rm = T
  24. ) +
  25. ggthemes::theme_map()
  26.  
  27. # support for coord_equal() coming soon! For now, you can do this...
  28. ggplotly(p, tooltip = "text") %>%
  29. layout(xaxis = list(scaleanchor = "y", scaleratio = 0.9))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement