Last active
May 16, 2018 11:16
-
-
Save seabbs/814c6a621612cddfbed0752be8775e91 to your computer and use it in GitHub Desktop.
splash image for getTBinR 5.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Get required packages - managed using pacman | |
if (!require(pacman)) install.packages("pacman"); library(pacman) | |
p_load("getTBinR") | |
p_load("ggplot2") | |
p_load("viridis") | |
p_load("dplyr") | |
p_load("forcats") | |
p_load("ggridges") | |
p_load_gh("thomasp85/patchwork") | |
## Pull TB data and summarise TB incidence rates by region using the median | |
tb_sum <- summarise_tb_burden(metric = "e_inc_100k", | |
stat = "median", | |
compare_all_regions = TRUE, | |
samples = 1000) | |
## Plot the median and IQR for each region | |
sum <- tb_sum %>% | |
rename(Region = area) %>% | |
ggplot(aes(x = year, y = e_inc_100k, col = Region, fill = Region)) + | |
geom_ribbon(alpha = 0.2, aes(ymin = e_inc_100k_lo, ymax = e_inc_100k_hi)) + | |
scale_color_viridis(discrete = TRUE) + | |
scale_fill_viridis(discrete = TRUE) + | |
geom_line(alpha = 0.6, size = 1.2) + | |
geom_point(size = 1.3) + | |
theme_minimal() + | |
facet_wrap(~Region, scales = "free_y") + | |
theme(legend.position = "none") + | |
labs(y = search_data_dict("e_inc_100k")$definition, | |
x = "Year", | |
title = "Regional Summary of Tuberculosis Incidence Rates - 2000 to 2016", | |
subtitle = "Median country level incidence rates (with 95% interquartile ranges) are shown") | |
## Get the full TB burden dataset (including MDR TB) | |
tb <- get_tb_burden() | |
## Plot the distribution of country level TB incidence rates using ggridges | |
dist <- tb %>% | |
rename(Region = g_whoregion) %>% | |
mutate(year = year %>% | |
factor(ordered = TRUE) %>% | |
fct_rev) %>% | |
ggplot(aes(x = e_inc_100k, y = year, col = Region, fill = Region)) + | |
geom_density_ridges(alpha = 0.6) + | |
scale_color_viridis(discrete = TRUE) + | |
scale_fill_viridis(discrete = TRUE) + | |
theme_minimal() + | |
facet_wrap(~Region, scales = "free_x") + | |
theme(legend.position = "none") + | |
labs(x = search_data_dict("e_inc_100k")$definition, | |
y = "Year", | |
title = "Distribution of Country Level Tuberculosis Incidence Rates by Region - 2000 to 2016", | |
caption = "By @seabbs | Made with getTBinR | Source: World Health Organisation") | |
## Map global TB incidence rates for 2016 using getTBinR | |
map <- map_tb_burden() + | |
labs(caption = "", | |
title = "Map of Tuberculosis Incidence Rates - 2016") | |
## Extract the top 10 high incidence countries in 2016. | |
high_inc_countries <- tb %>% | |
filter(year == 2016) %>% | |
arrange(desc(e_inc_100k)) %>% | |
slice(1:10) %>% | |
pull(country) | |
## Plot an overview of TB incidence rates in 2016. | |
high_inc_overview <- plot_tb_burden_overview(countries = high_inc_countries) + | |
labs(caption = "", | |
title = "10 Countries with the Highest Tuberculosis Incidence Rates - 2016") | |
## Compose storyboard | |
storyboard <- (map + high_inc_overview) / | |
(sum | dist) + | |
plot_layout(heights = c(1, 2)) | |
## Save storyboard | |
ggsave("storyboard.png", | |
storyboard, width = 20, height = 15, dpi = 330) |
Author
seabbs
commented
May 16, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment