Skip to content

Instantly share code, notes, and snippets.

@seabbs
Last active June 5, 2019 09:29
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/f4faca39a7906df2a5c2cc06b5489c3c to your computer and use it in GitHub Desktop.
Save seabbs/f4faca39a7906df2a5c2cc06b5489c3c to your computer and use it in GitHub Desktop.
Looking at the expenditure and funding gap for TB
# Install and load the package --------------------------------------------
#Use install.packages(c("getTBinR", "dplyr", "getTBinR")) to get required packages
library(getTBinR) #TB data + visualisations
library(dplyr) # For data manipulation
library(ggplot2) # For additional visualisations etc.
#For storyboards - install with commented out code
# install.packages("devtools")
# devtools::install_github("thomasp85/patchwork")
library(patchwork)
# 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 = (rcvd_tot_sources - exp_tot) / (1e6))
label <- "Difference between funding and expenditure (US Dollars (million))"
# 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 = "") +
theme(plot.title = element_text(size=22),
plot.subtitle = element_text(size=20))
# 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) +
theme(legend.position = "none") +
labs(title = "Countries with the larget TB spending gap",
subtitle = "Data from 2017",
caption = "")
# Plot incidence rates in these countries ----------------------------------
plot_inc <- plot_incidence_rates <- 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") +
theme(legend.position = "none") +
labs(title = "TB incidence rates",
subtitle = "For countries with the largest spending gap",
caption = "@seabbs | Using #getTBinR | Data sourced from: World Health Organization")
# Make storyboard ---------------------------------------------------------
storyboard <- (map) /
(plot_top + plot_inc)
## Save storyboard
ggsave("storyboard.png",
storyboard, width = 20, height = 15, dpi = 330)
@seabbs
Copy link
Author

seabbs commented Jun 5, 2019

storyboard

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