Created
January 27, 2017 14:10
-
-
Save expersso/8f2b1c5895326e9de4c6b24b7f7201ce to your computer and use it in GitHub Desktop.
Recreating FT chart on health spending and life expectancy in OECD countries
This file contains hidden or 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
library(tidyverse) | |
library(scales) | |
library(OECD) | |
library(grid) | |
library(gridExtra) | |
oecd <- c("AUS","AUT","BEL","CAN","CHL","CZE","DNK","EST","FIN","FRA", | |
"DEU","GRC","HUN","ISL","IRL","ISR","ITA","JPN","KOR","LVA", | |
"LUX","MEX","NLD","NZL","NOR","POL","PRT","SVK","SVN","ESP", | |
"SWE","CHE","TUR","GBR","USA") | |
spending <- get_dataset("SHA", list("HFTOT.HCTOT.HPTOT.VRPPPR", oecd)) | |
life <- get_dataset("HEALTH_STAT", list("EVIETOTA.EVIDUREV", oecd)) | |
df <- inner_join( | |
life %>% select("iso3c" = COU, obsTime, "life" = obsValue), | |
spending %>% select("iso3c" = LOCATION, obsTime, "spending" = obsValue) | |
) | |
df_other <- df %>% filter(!iso3c %in% c("USA", "JPN", "GBR")) | |
df_annotate <- df %>% filter(iso3c %in% c("USA", "JPN", "GBR")) | |
p <- ggplot(NULL, aes(x = spending, y = life, group = iso3c, color = iso3c)) + | |
geom_path(data = df_other, color = "grey80", size = 0.5) + | |
geom_path(data = df_annotate, size = 1) + | |
geom_text(aes(label = iso3c), filter(df_annotate, obsTime == 2014), | |
size = 4, vjust = -0.5) + | |
geom_point(data = filter(df_annotate, obsTime %in% c(1970, 2014)), size = 2) + | |
scale_color_manual(values = c("mediumblue", "olivedrab4", "violetred2")) + | |
scale_y_continuous(expand = c(0.1, 0.1)) + | |
theme(legend.position = "none") + | |
labs(x = "\nHealth spending per capita ($US 2010 PPP constant)", | |
y = "Life expectancy\n", | |
title = "Life expectancy has not risen in line with\nspending on healthcare", | |
subtitle = "Each line represents an OECD country") | |
grid.arrange(p, p + scale_x_log10(), nrow = 1) |
Author
expersso
commented
Jan 27, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment