NY.GDS.TOTL.ZS |>
left_join(GC.NLD.TOTL.GD.ZS |> select(iso2c, year, GC.NLD.TOTL.GD.ZS = value), by = c("iso2c", "year")) |>
left_join(NY.GNS.ICTR.ZS |> select(iso2c, year, NY.GNS.ICTR.ZS = value), by = c("iso2c", "year")) |>
left_join(NE.GDI.TOTL.ZS |> select(iso2c, year, NE.GDI.TOTL.ZS = value), by = c("iso2c", "year")) |>
rename(`Gross Domestic Saving` = value,
`Gross National Saving` = NY.GNS.ICTR.ZS,
`Public Saving` = GC.NLD.TOTL.GD.ZS,
`Gross Investment` = NE.GDI.TOTL.ZS) |>
mutate(`Gross Private Saving` = `Gross Domestic Saving` - `Public Saving`) |>
select(-`Public Saving`) |>
select(-iso3c, -variable) |>
gather(variable, value, -iso2c, -year) |>
filter(iso2c %in% c("JP")) |>
left_join(iso2c, by = "iso2c") |>
year_to_date() |>
ggplot() + xlab("") + ylab("% of GDP") + theme_minimal() +
geom_line(aes(x = date, y = value/100, color = variable, linetype = variable)) +
scale_color_manual(values = viridis(5)[1:4]) +
theme(legend.title = element_blank(),
legend.position = c(0.2, 0.2)) +
scale_x_date(breaks = seq(1950, 2100, 5) |> paste0("-01-01") |> as.Date(),
labels = date_format("%Y")) +
scale_y_continuous(breaks = 0.01*seq(-60, 60, 2),
labels = scales::percent_format(accuracy = 1))