Skip to content

Instantly share code, notes, and snippets.

@seabbs
Created June 7, 2019 10:37
Show Gist options
  • Save seabbs/39a78ed69c65132c1e0a44a75d0eabf6 to your computer and use it in GitHub Desktop.
Save seabbs/39a78ed69c65132c1e0a44a75d0eabf6 to your computer and use it in GitHub Desktop.
Looking at normalised spending gap for global Tuberculosis funding
# Install and load the package --------------------------------------------
if(!require(pacman))install.packages("pacman")
pacman::p_load('dplyr', 'ggplot2', 'getTBinR')
pacman::p_load_gh('thomasp85/patchwork')
pacman::p_load_gh('bbc/bbplot')
# Look at available datasets\ ---------------------------------------------
available_datasets
# Download data of interest -----------------------------------------------
tb <- get_tb_burden(additional_datasets = "Expenditure and utilisation")
dict <- get_data_dict()
# Look up variables -------------------------------------------------------
search_data_dict(dataset = "Expenditure and utilisation")
## expenditure (exp_tot) and funding (rcvd_tot_sources) are likely to be of some interest
tb <- tb %>%
mutate(spending_gap = 100 * (rcvd_tot_sources - exp_tot) / rcvd_tot_sources) %>%
mutate(spending_gap = replace(spending_gap, rcvd_tot_sources < 10e6 | e_inc_100k < 10,
NA))
label <- "% difference between funding and expenditure"
# Map budget gap ----------------------------------------------------------
map <- map_tb_burden(df = tb, metric = "spending_gap",
metric_label = label,
year = 2017) +
labs(title = "Tuberculosis (TB) spending gap",
subtitle = paste0(label, " - data from 2017"),
caption = "") +
bbc_style() +
theme(panel.background = element_blank(),
axis.text = element_blank())
# Get countries with largest spending gap ---------------------------------
largest_gap_countries <- tb %>%
filter(year == 2017) %>%
arrange(desc(spending_gap)) %>%
slice(1:10) %>%
pull(country)
# Plot countries with largest spending gap --------------------------------
plot_top <- plot_tb_burden_overview(df = tb,
countries = largest_gap_countries,
metric = "spending_gap",
metric_label = label,
year = 2017) +
bbc_style() +
theme(legend.position = "none") +
labs(subtitle = "Countries with the larget % spending \n gap",
caption = "")
# Plot incidence rates in these countries ----------------------------------
plot_inc <- plot_tb_burden_summary(df = tb,
countries = largest_gap_countries,
stat = "rate",
compare_to_region = FALSE,
compare_all_regions = FALSE,
facet = "Area",
scales = "free_y") +
bbc_style() +
theme(legend.position = "none", plot.caption = element_text(hjust = 1)) +
labs(
subtitle = "TB incidence rates - for countries with the largest % spending gap",
caption = "@seabbs | Using #getTBinR | Data sourced from: World Health Organization | Countries with funding below 10 million dollars or with TB incidence rates below 10 per 100,000 people have been removed.")
# Make storyboard ---------------------------------------------------------
storyboard <- (map + plot_top + plot_layout(widths = c(5, 2))) /
(plot_inc)
## Save storyboard
ggsave("storyboard.png",
storyboard, width = 20, height = 15, dpi = 330)
@seabbs
Copy link
Author

seabbs commented Jun 7, 2019

storyboard-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment