Created
March 16, 2023 23:25
-
-
Save jkr216/f5de545680522d7f4356bf8d49353783 to your computer and use it in GitHub Desktop.
core goods and core services chart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r include = FALSE} | |
library(tidyverse) | |
library(tidyquant) | |
library(timetk) | |
library(readxl) | |
library(plotly) | |
library(scales) | |
library(formattable) | |
library(fredr) | |
library(gt) | |
library(gtExtras) | |
library(ggtext) | |
``` | |
```{r} | |
core_goods_services <- | |
tibble( | |
symbol = c("CUUR0000SACL1E", "CUSR0000SASLE"), | |
name = c("core goods", "core services") | |
) %>% | |
tq_get(get = "economic.data", | |
from = "1980-01-01") | |
core_goods_services %>% | |
group_by(name) %>% | |
mutate(yoy = price/lag(price, 12) -1) %>% | |
drop_na() %>% | |
ggplot(aes(x = date, | |
y = yoy, | |
fill = name))+ | |
geom_col(show.legend = T, | |
position = position_dodge()) + | |
scale_y_continuous( | |
labels = percent_format(accuracy = 1), | |
breaks = pretty_breaks(10) | |
) + | |
theme_minimal( | |
) + | |
scale_fill_manual( | |
values = c("orange", "steelblue") | |
) + | |
scale_x_date( | |
date_labels = "%Y", | |
date_breaks = "4 years" | |
) + | |
labs(x = "", | |
y = "", | |
title = "Core Goods and Services CPI YoY Change", | |
fill = "") + | |
theme(legend.position = c(.3, .9), | |
legend.margin=margin(0,0,0,-10), | |
legend.box.margin=margin(-5,-5,-5,-5)) | |
``` | |
```{r} | |
core_goods_services %>% | |
group_by(name) %>% | |
mutate(yoy = price/lag(price, 12) -1) %>% | |
drop_na() %>% | |
filter(date >= "2000-01-01") %>% | |
ggplot(aes(x = date, | |
y = yoy, | |
fill = name))+ | |
geom_col(show.legend = T, | |
position = position_dodge()) + | |
scale_y_continuous( | |
labels = percent_format(accuracy = 1), | |
breaks = pretty_breaks(10) | |
) + | |
theme_minimal( | |
) + | |
scale_fill_manual( | |
values = c("orange", "steelblue") | |
) + | |
scale_x_date( | |
date_labels = "%Y", | |
date_breaks = "2 years" | |
) + | |
labs(x = "", | |
y = "", | |
title = "Core Goods and Services CPI YoY Change", | |
fill = "") + | |
theme(legend.position = c(.3, .9), | |
legend.margin=margin(0,0,0,-10), | |
legend.box.margin=margin(-5,-5,-5,-5)) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment