library(tidyverse)
library(readxl)
setwd("~/Code/2105.bea/")
theme_custom <- function () {
theme(axis.text.x = element_blank(),
axis.text.y = element_text(colour="white"),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
panel.background = element_rect(fill = "#202124"),
panel.grid = element_blank(),
plot.subtitle = element_text(color = "white"),
plot.title = element_text(color = "white"),
plot.background = element_rect(fill = "#202124"))}
raw <- read_excel("raw/gdp1q21_adv.xlsx", sheet = 4, skip = 3)
read_excel("raw/gdp1q21_adv.xlsx", sheet = 4, skip = 4) %>%
select(2, 4, 8) %>%
rename(category = 1,
`2020` = 2,
`2021` = 3) %>%
mutate(`2020` = as.numeric(`2020`),
`2021` = as.numeric(`2021`)) %>%
mutate(alt_2021 = `2020`*1.02,
delta = (`2021` - alt_2021) / alt_2021) %>%
filter(category %in% c("Recreational goods and vehicles",
"Information processing equipment",
"Furnishings and durable household equipment",
"Residential",
"Health care",
"Goods",
"Transportation equipment",
"Transportation services",
"Gasoline and other energy goods",
"Food services and accommodations",
"Structures",
"Services",
"Recreation services",
"Entertainment, literary, and artistic originals",
"Software")) %>%
slice(-1, -5, -18, -19) %>%
mutate(category = recode(category,
"Services" = "Exports of services",
"Structures" = "Investments in structures",
"Food services and acommmodations" = "Food and accommodations",
"Goods" = "Goods exports",
"Residential" = "Residential investment",
"Software" = "Software investment")) %>%
ggplot(aes(reorder(category, delta), delta, width = `2021`/10000,
label = scales::percent(delta,accuracy = 1))) +
geom_col(fill = "#F72485") +
coord_flip() +
geom_text(aes(y = delta + .03 * sign(delta)),
color = "#F72485") +
#ggthemes::theme_few() +
theme_custom() +
labs(x = "", y = "",
title = "\nEconomic Winners and Losers",
subtitle = "How first-quarter output compared with output in a hypothetical economy with no pandemic.
n") +
theme(legend.position = "none")
ggsave("fig/bar.png", width = 10, height = 6)