# 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")