Skip to content

Instantly share code, notes, and snippets.

@seabbs
Created January 11, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seabbs/69c1a48681d37bfacc321a56b9a714b2 to your computer and use it in GitHub Desktop.
Save seabbs/69c1a48681d37bfacc321a56b9a714b2 to your computer and use it in GitHub Desktop.
Explore case detection and incidence rates in the WHO Tuberculosis data
# install.packages("getTBinR")
library(getTBinR)
# install.packages("tidyverse")
library(tidyverse)
# install.packages("gridExtra")
library(gridExtra)
# Get the data
tb_burden <- get_tb_burden(download_data = TRUE, save = TRUE)
dict <- get_data_dict(download_data = TRUE, save = TRUE)
# Look up variables with dectection in their definition
search_data_dict(def = "detection")
# Map case detection in 2016
map_tb_burden(metric = "c_cdr", year = 2016)
# Map incidence rates in 2016
map_tb_burden(year = 2016)
# Get countries with lowest case detection rates
low_detect_countries <- tb_burden %>%
filter(year == 2016) %>%
group_by(country) %>%
summarise(c_cdr = min(c_cdr)) %>%
ungroup %>%
arrange(c_cdr) %>%
slice(1:20) %>%
pull(country) %>%
unique
#Overview of 20 countries with lowest case detection rates
p1 <- plot_tb_burden_overview(metric = "c_cdr",
countries = low_detect_countries) +
theme(legend.position = "none")
# Overview of 20 countries with highest incidence rates
high_inc_countries <- tb_burden %>%
filter(year == 2016) %>%
group_by(country) %>%
summarise(e_inc_100k = max(e_inc_100k)) %>%
ungroup %>%
arrange(desc(e_inc_100k)) %>%
slice(1:20) %>%
pull(country) %>%
unique
p2 <- plot_tb_burden_overview(countries = high_inc_countries)
grid.arrange(p1, p2, ncol = 2, widths = c(0.46, 0.54))
## Countries with both highest incidence and lowest case detection rates
high_inc_low_detect <- intersect(low_detect_countries, high_inc_countries)
# Trends over time in cases detection rates in countries that are both highest 20 incidence and lowest 20 case detection rate
p3 <- plot_tb_burden(metric = "c_cdr",
countries = high_inc_low_detect,
facet = "country", scales = "fixed")
# Trends in incidence rates over time in countries that have both lowest case detection and highest incidence rates
p4 <- plot_tb_burden(countries = high_inc_low_detect,
facet = "country", scales = "free_y")
grid.arrange(p3, p4, ncol = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment