Skip to content

Instantly share code, notes, and snippets.

@flashton2003
Created August 31, 2018 03:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flashton2003/757f42bab3655239337389b0b89a2924 to your computer and use it in GitHub Desktop.
Save flashton2003/757f42bab3655239337389b0b89a2924 to your computer and use it in GitHub Desktop.
library(readr)
library(dplyr)
library(cartogram)
library(tmap)
library(maptools)
data(wrld_simpl)
all_tb_burden <- read_delim("~/all_tb_burden.tsv", "\t", escape_double = FALSE, trim_ws = TRUE)
y = '2016'
this_years_tb <- filter(all_tb_burden, all_tb_burden$year == y)
this_years_wrld_tb <- merge(wrld_simpl, this_years_tb, by.x = "NAME", by.y = 'Rcountry')
this_years_wrld_tb$TB_cases <- this_years_wrld_tb$TB_cases + 1
this_years_wrld_tb <- spTransform(this_years_wrld_tb, CRS("+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))
this_years_wrld_tb_cont <- cartogram_cont(this_years_wrld_tb, "TB_cases", itermax = 5)
tm_shape(this_years_wrld_tb_cont) + tm_polygons("TB_cases", style = "jenks") + tm_layout(frame = FALSE, legend.position = c('left', 'bottom'), title = y, title.position = c('left', 'top'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment