Skip to content

Instantly share code, notes, and snippets.

@seabbs
Last active January 31, 2018 11:33
Show Gist options
  • Save seabbs/936e07f5668307d65681088652a54f36 to your computer and use it in GitHub Desktop.
Save seabbs/936e07f5668307d65681088652a54f36 to your computer and use it in GitHub Desktop.
Exploring HIV and TB incidence in high burden countries
# install.packages("getTBinR")
library(getTBinR)
# install.packages("tidyverse")
library(tidyverse)
# install.packages("gridExtra")
library(gridExtra)
# Get the data - WHO data
tb_df <- get_tb_burden()
dict <- get_data_dict()
# Look up variables with mortality in their definition
search_data_dict(def = "incidence")
# Map incidence rates in 2016
map_tb_burden(tb_df, dict, metric = "e_inc_100k", year = 2016)
ggsave("map_inc_2016_TB.png", width = 8, height = 4, dpi = 330)
# Get countries with highest incidence rates in the data
high_inc_countries <- tb_df %>%
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
#Find Proportion of cases that have HIV
search_data_dict(def = "HIV")
#Overview of 20 countries with highest percentages of HIV in TB cases
map_tb_burden(tb_df, dict, metric = "e_tbhiv_prct", year = 2016)
ggsave("map_HIV_per_in_TB.png", width = 8, height = 4, dpi = 330)
## Get countries with highest percentage of HIV in TB
high_HIV_in_TB_countries <- tb_df %>%
filter(year == 2016) %>%
group_by(country) %>%
summarise(e_tbhiv_prct = max(e_tbhiv_prct)) %>%
ungroup %>%
arrange(desc(e_tbhiv_prct)) %>%
slice(1:20) %>%
pull(country) %>%
unique
## Intersection between high incidence and HIV
high_inc_high_HIV_countries <- intersect(high_inc_countries, high_HIV_in_TB_countries)
high_inc_high_HIV_countries
## Trend overview in high inc and high HIV countries - TB incidence rates
p1 <- plot_tb_burden_overview(tb_df, dict, metric = "e_inc_100k",
countries = high_inc_high_HIV_countries) +
theme(legend.position = "none")
## Trend overview in high inc and high HIV countries - Percentage of cases with HIV
p2 <- plot_tb_burden_overview(tb_df, dict, metric = "e_tbhiv_prct",
countries = high_inc_high_HIV_countries)
cp1 <- grid.arrange(p1, p2, ncol = 2, widths = c(0.46, 0.54))
cp1
ggsave("overview_high_inc_high_HIV_per.png", cp1, width = 16, height = 8, dpi = 330)
## Trend overview in high inc and high HIV countries - TB incidence rates
p3 <- plot_tb_burden(tb_df, dict, metric = "e_inc_100k",
countries = high_inc_high_HIV_countries,
facet = "country", scales = "free_y")
## Trends in high inc and high HIV countries - Percentage of cases with HIV
p4 <- plot_tb_burden(tb_df, dict, metric = "e_tbhiv_prct",
countries = high_inc_high_HIV_countries,
facet = "country", scales = "free_y")
cp2 <- grid.arrange(p3, p4, ncol = 2)
cp2
ggsave("trends_high_inc_high_HIV_per.png", cp2, width = 16, height = 8, dpi = 330)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment