Z1_csv_var %>%
mutate(line = parse_number(pos)) %>%
filter(table == "B101E",
line %in% c(14, 2)) %>%
left_join(Z1_csv, by = c("variable", "table")) %>%
select(date, table, pos, variable_desc, value) %>%
left_join(gdp_Q %>% rename(gdp = value), by = "date") %>%
mutate(value = value / gdp) %>%
ggplot(.) + theme_minimal() +
geom_line(aes(x = date, y = value, color = variable_desc, linetype = variable_desc)) +
theme(legend.title = element_blank(),
legend.position = c(0.5, 0.9)) +
scale_x_date(breaks = seq(1930, 2020, 5) %>% paste0("-01-01") %>% as.Date,
limits = c(1950, 2020) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y")) +
ylab("% of GDP") + xlab("") +
geom_rect(data = nber_recessions %>%
filter(Peak > as.Date("1950-01-01")),
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_color_manual(values = viridis(4)[1:3]) +
scale_y_continuous(breaks = 0.01*seq(0, 600, 20),
labels = scales::percent_format(accuracy = 1),
limits = c(0, 2.6))
Z1_csv_var %>%
mutate(line = parse_number(pos)) %>%
filter(table == "B101E",
line %in% c(1, 9, 40)) %>%
left_join(Z1_csv, by = c("variable", "table")) %>%
select(date, table, pos, variable_desc, value) %>%
left_join(gdp_Q %>% rename(gdp = value), by = "date") %>%
mutate(value = value / gdp) %>%
ggplot(.) + theme_minimal() +
geom_line(aes(x = date, y = value, color = variable_desc, linetype = variable_desc)) +
theme(legend.title = element_blank(),
legend.position = c(0.4, 0.9)) +
scale_x_date(breaks = seq(1930, 2020, 5) %>% paste0("-01-01") %>% as.Date,
limits = c(1950, 2020) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y")) +
ylab("% of GDP") + xlab("") +
geom_rect(data = nber_recessions %>%
filter(Peak > as.Date("1950-01-01")),
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_color_manual(values = viridis(4)[1:3]) +
scale_y_continuous(breaks = 0.01*seq(-100, 700, 50),
labels = scales::percent_format(accuracy = 1))
Z1_csv_var %>%
mutate(line = parse_number(pos)) %>%
filter(table == "B101E",
line %in% c(23, 27, 3)) %>%
left_join(Z1_csv, by = c("variable", "table")) %>%
select(date, table, pos, variable_desc, value) %>%
left_join(gdp_Q %>% rename(gdp = value), by = "date") %>%
mutate(value = value / gdp) %>%
ggplot(.) + theme_minimal() +
geom_line(aes(x = date, y = value, color = variable_desc, linetype = variable_desc)) +
theme(legend.title = element_blank(),
legend.position = c(0.4, 0.9)) +
scale_x_date(breaks = seq(1930, 2020, 5) %>% paste0("-01-01") %>% as.Date,
limits = c(1950, 2020) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y")) +
ylab("% of GDP") + xlab("") +
geom_rect(data = nber_recessions %>%
filter(Peak > as.Date("1950-01-01")),
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_color_manual(values = viridis(4)[1:3]) +
scale_y_continuous(breaks = 0.01*seq(-100, 600, 10),
labels = scales::percent_format(accuracy = 1))
Z1_csv_var %>%
mutate(line = parse_number(pos)) %>%
filter(table == "B101E",
line %in% c(45, 46)) %>%
left_join(Z1_csv, by = c("variable", "table")) %>%
select(date, table, pos, variable_desc, value) %>%
left_join(gdp_Q %>% rename(gdp = value), by = "date") %>%
mutate(value = value / gdp) %>%
ggplot(.) + theme_minimal() +
geom_line(aes(x = date, y = value, color = variable_desc, linetype = variable_desc)) +
theme(legend.title = element_blank(),
legend.position = c(0.4, 0.9)) +
scale_x_date(breaks = seq(1930, 2020, 5) %>% paste0("-01-01") %>% as.Date,
limits = c(1950, 2020) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y")) +
ylab("% of GDP") + xlab("") +
geom_rect(data = nber_recessions %>%
filter(Peak > as.Date("1950-01-01")),
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_color_manual(values = viridis(4)[1:3]) +
scale_y_continuous(breaks = 0.01*seq(-100, 600, 10),
labels = scales::percent_format(accuracy = 1))
Z1_csv_var %>%
filter(table == "B101E") %>%
left_join(Z1_csv %>%
filter(date == as.Date("2019-12-31")),
by = c("variable", "table")) %>%
select(table, pos, variable_desc, value) %>%
mutate(value = round(value/1000) %>% paste0("$ ", ., " Bn")) %>%
{if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}