~/data/wdi/

Nobs - Javascript

NY.GDS.TOTL.ZS %>%
  left_join(iso2c, by = "iso2c") %>%
  group_by(iso2c, Iso2c) %>%
  rename(value = `NY.GDS.TOTL.ZS`) %>%
  mutate(value = round(value, 1)) %>%
  summarise(Nobs = n(),
            `Year 1` = first(year),
            `Net Saving 1 (%)` = first(value),
            `Year 2` = last(year),
            `Net Saving 2 (%)` = last(value)) %>%
  arrange(-Nobs) %>%
  mutate(Flag = gsub(" ", "-", str_to_lower(Iso2c)),
         Flag = paste0('<img src="../../bib/flags/vsmall/', Flag, '.png" alt="Flag">')) %>%
  select(Flag, everything()) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F, escape = F) else .}

Individual Countries

Japan

NY.GDS.TOTL.ZS %>%
  left_join(GC.NLD.TOTL.GD.ZS, by = c("iso2c", "year")) %>%
  left_join(NY.GNS.ICTR.ZS, by = c("iso2c", "year")) %>%
  left_join(NE.GDI.TOTL.ZS, by = c("iso2c", "year")) %>%
  rename(`Gross Domestic Saving` = NY.GDS.TOTL.ZS,
         `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`) %>%
  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, 2020, 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))

Germany

NY.GDS.TOTL.ZS %>%
  left_join(GC.NLD.TOTL.GD.ZS, by = c("iso2c", "year")) %>%
  left_join(NY.GNS.ICTR.ZS, by = c("iso2c", "year")) %>%
  left_join(NE.GDI.TOTL.ZS, by = c("iso2c", "year")) %>%
  rename(`Gross Domestic Saving` = NY.GDS.TOTL.ZS,
         `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`) %>%
  gather(variable, value,- iso2c, -year) %>%
  filter(iso2c %in% c("DE")) %>%
  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.3, 0.85)) +
  scale_x_date(breaks = seq(1950, 2020, 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))

France

NY.GDS.TOTL.ZS %>%
  left_join(GC.NLD.TOTL.GD.ZS, by = c("iso2c", "year")) %>%
  left_join(NY.GNS.ICTR.ZS, by = c("iso2c", "year")) %>%
  left_join(NE.GDI.TOTL.ZS, by = c("iso2c", "year")) %>%
  rename(`Gross Domestic Saving` = NY.GDS.TOTL.ZS,
         `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`) %>%
  gather(variable, value,- iso2c, -year) %>%
  filter(iso2c %in% c("FR")) %>%
  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, 2020, 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))

China

NY.GDS.TOTL.ZS %>%
  left_join(GC.NLD.TOTL.GD.ZS, by = c("iso2c", "year")) %>%
  rename(`Gross Domestic Saving` = NY.GDS.TOTL.ZS, `Public Saving` = GC.NLD.TOTL.GD.ZS) %>%
  mutate(`Gross Private Saving` = `Gross Domestic Saving` + `Public Saving`) %>%
  gather(variable, value,- iso2c, -year) %>%
  filter(iso2c %in% c("CN")) %>%
  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.55)) +
  scale_x_date(breaks = seq(1950, 2020, 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))

China, France, Germany

NY.GDS.TOTL.ZS %>%
  filter(iso2c %in% c("CN", "FR", "DE")) %>%
  left_join(iso2c, by = "iso2c") %>%
  year_to_date %>%
  ggplot(.) + 
  geom_line(aes(x = date, y = NY.GDS.TOTL.ZS/100, color = Iso2c, linetype = Iso2c)) + 
  theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  theme(legend.title = element_blank(),
        legend.position = c(0.1, 0.85)) +
  scale_x_date(breaks = seq(1950, 2020, 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)) +
  xlab("") + ylab("Gross domestic savings (% of GDP)")

Spain, United Kingdom, United States

NY.GDS.TOTL.ZS %>%
  filter(iso2c %in% c("US", "GB", "ES")) %>%
  left_join(iso2c, by = "iso2c") %>%
  year_to_date %>%
  ggplot(.) + 
  geom_line(aes(x = date, y = NY.GDS.TOTL.ZS/100, color = Iso2c, linetype = Iso2c)) + 
  theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  theme(legend.title = element_blank(),
        legend.position = c(0.8, 0.9)) +
  scale_x_date(breaks = seq(1950, 2020, 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)) +
  xlab("") + ylab("Gross domestic savings (% of GDP)")

Argentina, Chile, Venezuela

NY.GDS.TOTL.ZS %>%
  filter(iso2c %in% c("AR", "CL", "VE")) %>%
  left_join(iso2c, by = "iso2c") %>%
  year_to_date %>%
  ggplot(.) + 
  geom_line(aes(x = date, y = NY.GDS.TOTL.ZS/100, color = Iso2c, linetype = Iso2c)) + 
  theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.9)) +
  scale_x_date(breaks = seq(1950, 2020, 5) %>% paste0("-01-01") %>% as.Date,
               labels = date_format("%y")) +
  scale_y_continuous(breaks = 0.01*seq(-60, 60, 5),
                     labels = scales::percent_format(accuracy = 1)) +
  xlab("") + ylab("Gross domestic savings (% of GDP)")

Greece, Hong Kong, Mexico

NY.GDS.TOTL.ZS %>%
  filter(iso2c %in% c("GR", "HK", "MX")) %>%
  left_join(iso2c, by = "iso2c") %>%
  year_to_date %>%
  ggplot(.) + 
  geom_line(aes(x = date, y = NY.GDS.TOTL.ZS/100, color = Iso2c, linetype = Iso2c)) + 
  theme_minimal() + scale_color_manual(values = viridis(4)[1:3]) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.15)) +
  scale_x_date(breaks = seq(1950, 2020, 5) %>% paste0("-01-01") %>% as.Date,
               labels = date_format("%y")) +
  scale_y_continuous(breaks = 0.01*seq(-60, 60, 5),
                     labels = scales::percent_format(accuracy = 1)) +
  xlab("") + ylab("Gross domestic savings (% of GDP)")