Table 1.1.11. Real Gross Domestic Product - Percent Change From Quarter One Year Ago (Q) - T10101 - T10111

Data - BEA

Ex 1: Real GDP Growth (Y/Y)

Code
T10111_Q |>
  quarter_to_date() |>
  filter(LineNumber == 1) |>
  ggplot() + theme_minimal() +
  geom_line(aes(x = date, y = DataValue), color = viridis(1)) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey50") +
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1948-01-01")),
            aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
            fill = 'grey', alpha = 0.5) +
  scale_x_date(breaks = seq(1930, 2100, 10) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  ylab("Real GDP, % change Y/Y") + xlab("")

Ex 2: 1938, 1958, 1978, 1998, 2018 Table

Code
T10111_Q |>
  quarter_to_date() |>
  mutate(year = year(date)) |>
  filter(year %in% c(1938, 1958, 1978, 1998, 2018),
         month(date) == 3) |>
  group_by(year) |>
  mutate(value = round(DataValue, 2)) |>
  ungroup() |>
  select(LineNumber, LineDescription, year, value) |>
  spread(year, value) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}

Ex 3: GDP vs Gross Domestic Income

Code
T10111_Q |>
  quarter_to_date() |>
  filter(LineNumber %in% c(1, 31)) |>
  mutate(LineDescription = ifelse(LineNumber == 1, "GDP", "GDI")) |>
  ggplot() + theme_minimal() +
  geom_line(aes(x = date, y = DataValue, color = LineDescription)) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey50") +
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1948-01-01")),
            aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
            fill = 'grey', alpha = 0.5) +
  scale_x_date(breaks = seq(1930, 2100, 10) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_color_manual(values = viridis(2)) +
  theme(legend.title = element_blank(),
        legend.position = "bottom") +
  ylab("% change Y/Y") + xlab("")