Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.