Skip to content

Instantly share code, notes, and snippets.

@christophsax
Last active February 11, 2018 12:05
Show Gist options
  • Save christophsax/ae3a4b122ae52ba0f8e514f47d0ecae4 to your computer and use it in GitHub Desktop.
Save christophsax/ae3a4b122ae52ba0f8e514f47d0ecae4 to your computer and use it in GitHub Desktop.
Comparison of Life Expectancy

Life Expectancy

# devtools::install_github("christophsax/tsbox")
library(tsbox)
stopifnot(packageVersion("tsbox") >= "0.0.11.2")
suppressMessages(library(tidyverse))
library(wbstats)

# # Search
# wb_cachelist <- wbcache()
# le_vars <- wbsearch(pattern = "Life expectancy at birth", cache = wb_cachelist)

# Download
dta <- wb(indicator = "SP.DYN.LE00.IN") %>% 
  as_data_frame() %>% 
  select(iso = iso3c, time = date, value) %>% 
  arrange(time)

dta %>% 
  filter(iso %in% c("CHE", "USA", "WLD")) %>% 
  ts_diff() %>% 
  ts_trend() %>% 
  ts_plot(title = "Increase in Life Expectancy", subtitle = "smoothed")
#> 'span' automatically set to 0.339. Set manually to change degree of smoothing
#> 'span' automatically set to 0.935. Set manually to change degree of smoothing
#> 'span' automatically set to 0.909. Set manually to change degree of smoothing

dta %>% 
  filter(iso %in% c("CHE", "USA", "WLD")) %>% 
  ts_plot(title = "Life Expectancy", subtitle = "in years")

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