Energy

Data - Fred

Info

source dataset .html .RData

fred

energy

2024-10-24 2024-11-01

Data on energy

source dataset .html .RData

ec

WOB

2024-09-15 2024-08-25

eurostat

ei_isen_m

2024-11-01 2024-10-09

eurostat

nrg_bal_c

2023-12-31 2024-10-08

eurostat

nrg_pc_202

2024-10-24 2024-10-08

eurostat

nrg_pc_203

2023-06-11 2024-10-08

eurostat

nrg_pc_203_c

2024-10-24 2024-10-08

eurostat

nrg_pc_203_h

2024-10-24 2024-11-01

eurostat

nrg_pc_203_v

2024-10-24 2024-10-08

eurostat

nrg_pc_204

2024-10-24 2024-11-01

eurostat

nrg_pc_205

2023-06-11 2024-10-08

fred

energy

2024-10-24 2024-11-01

iea

world_energy_balances_highlights_2022

2024-06-20 2023-04-24

wb

CMO

2024-06-20 2024-05-23

wdi

EG.GDP.PUSE.KO.PP.KD

2024-09-18 2024-09-18

wdi

EG.USE.PCAP.KG.OE

2024-09-18 2024-09-18

yahoo

energy

2024-10-29 2024-10-29

Data on industry

source dataset .html .RData

ec

INDUSTRY

2024-09-15 2023-10-01

eurostat

ei_isin_m

2024-11-01 2024-10-09

eurostat

htec_trd_group4

2024-11-01 2024-10-08

eurostat

nama_10_a64

2024-10-24 2024-10-08

eurostat

nama_10_a64_e

2024-10-24 2024-10-08

eurostat

namq_10_a10_e

2024-10-24 2024-10-08

eurostat

road_eqr_carmot

2024-10-09 2024-10-08

eurostat

sts_inpp_m

2024-06-24 2024-10-08

eurostat

sts_inppd_m

2024-10-09 2024-10-08

eurostat

sts_inpr_m

2024-10-09 2024-10-08

eurostat

sts_intvnd_m

2024-10-31 2024-10-31

fred

industry

2024-10-24 2024-11-01

oecd

ALFS_EMP

2024-04-16 2024-05-12

oecd

BERD_MA_SOF

2024-04-16 2023-09-09

oecd

GBARD_NABS2007

2024-04-16 2023-11-22

oecd

MEI_REAL

2024-05-12 2024-05-03

oecd

MSTI_PUB

2024-09-15 2023-10-04

oecd

SNA_TABLE4

2024-09-15 2024-04-30

wdi

NV.IND.EMPL.KD

2024-01-06 2024-09-18

wdi

NV.IND.MANF.CD

2024-09-18 2024-09-18

wdi

NV.IND.MANF.ZS

2024-01-06 2024-09-18

wdi

NV.IND.TOTL.KD

2024-01-06 2024-09-18

wdi

NV.IND.TOTL.ZS

2024-01-06 2024-09-18

wdi

SL.IND.EMPL.ZS

2024-01-06 2024-09-18

wdi

TX.VAL.MRCH.CD.WT

2024-01-06 2024-09-18

LAST_COMPILE

LAST_COMPILE
2024-11-01

Last

date Nobs
2024-10-28 3

variable

variable Variable Nobs
CP0451MI15EA20M086NEST Harmonized Index of Consumer Prices: Electricity for Euro area (20 countries) 298
CP0452MI15EA20M086NEST Harmonized Index of Consumer Prices: Gas for Euro area (20 countries) 298
CP0722MI15EA20M086NEST Harmonized Index of Consumer Prices: Transport services for Euro area (20 countries) 298
CPIAUCSL Consumer Price Index for All Urban Consumers: All Items in U.S. City Average 933
CUSR0000SEHF01 Consumer Price Index for All Urban Consumers: Electricity in U.S. City Average 873
CUSR0000SEHF02 Consumer Price Index for All Urban Consumers: Utility (Piped) Gas Service in U.S. City Average 873
CUSR0000SETB Consumer Price Index for All Urban Consumers: Motor Fuel in U.S. City Average 693
DCOILBRENTEU Crude Oil Prices: Brent - Europe 9769
DCOILWTICO Crude Oil Prices: West Texas Intermediate (WTI) - Cushing, Oklahoma 10128
DGHERG3A086NBEA Personal consumption expenditures: Services: Household utilities: Natural gas (chain-type price index) 95
GASREGW US Regular All Formulations Gas Price 1785
IR10110 Import Price Index (End Use): Natural Gas 517
MHHNGSP Henry Hub Natural Gas Spot Price 333
MICH University of Michigan: Inflation Expectation 561
NYGDPMKTPCDWLD Gross Domestic Product for World 64
OILPRODWLD World production of Oil, Unit: Ktoe, Source: OECD 51
PNGASEUUSDM Global price of Natural gas, EU 477
WPU0531 Producer Price Index by Commodity: Fuels and Related Products and Power: Natural Gas 693
WTISPLC Spot Crude Oil Price: West Texas Intermediate (WTI) 945

Electricity, Natural gas

Since 2020

Inflation (1st difference)

Code
energy %>%
  filter(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02", "CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST")) %>%
  select(date, variable, value) %>%
  group_by(variable) %>%
  arrange(date) %>%
  mutate(value = value/lag(value, 12) - 1) %>%
  filter(date >= as.Date("2020-01-01")) %>%
  mutate(country = case_when(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02") ~ "United States (CPI)",
                             variable %in% c("CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST") ~ "Euro area (HICP)"),
         type = case_when(variable %in% c("CUSR0000SEHF01", "CP0451MI15EA20M086NEST") ~ "Electricity",
                          variable %in% c("CUSR0000SEHF02", "CP0452MI15EA20M086NEST") ~ "Natural gas")) %>%
  na.omit %>%
  ggplot(.) + geom_line(aes(x = date, y = value, color = country, linetype = type)) + theme_minimal() +
  scale_x_date(breaks = seq.Date(from = as.Date("2020-01-01"), to = Sys.Date(), by = "2 months"),
               labels = scales::date_format("%b %Y")) + 
  scale_y_continuous(breaks = 0.01*seq(-60, 100, 5),
                     labels = scales::percent_format(accuracy = 1)) + 
  scale_color_manual(values = c("#003399", "#B22234")) +
  xlab("") + ylab("Inflation (%)") +
  theme(legend.position = c(0.3, 0.78),
        legend.title = element_blank(),
        axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
  geom_vline(xintercept = as.Date("2022-06-01"), linetype = "dotted") + 
  geom_vline(xintercept = as.Date("2022-10-01"), linetype = "dotted")

Inflation Facet

Code
energy %>%
  filter(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02", "CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST")) %>%
  select(date, variable, value) %>%
  group_by(variable) %>%
  arrange(date) %>%
  mutate(value = value/lag(value, 12) - 1) %>%
  filter(date >= as.Date("2021-01-01")) %>%
  mutate(country = case_when(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02") ~ "United States (CPI)",
                             variable %in% c("CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST") ~ "Euro area (HICP)"),
         type = case_when(variable %in% c("CUSR0000SEHF01", "CP0451MI15EA20M086NEST") ~ "Electricity",
                          variable %in% c("CUSR0000SEHF02", "CP0452MI15EA20M086NEST") ~ "Natural gas")) %>%
  na.omit %>%
  ggplot(.) + geom_line(aes(x = date, y = value, color = country)) + theme_minimal() +
  scale_x_date(breaks = seq.Date(from = as.Date("2021-03-01"), to = Sys.Date(), by = "6 months"),
               labels = scales::date_format("%b %Y")) + 
  scale_y_continuous(breaks = 0.01*seq(-60, 100, 5),
                     labels = scales::percent_format(accuracy = 1)) + 
  scale_color_manual(values = c("#003399", "#B22234")) +
  xlab("") + ylab("Inflation (%)") +
  theme(legend.position = "top",
        legend.title = element_blank(),
        axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
  geom_vline(xintercept = as.Date("2022-06-01"), linetype = "dotted") + 
  geom_vline(xintercept = as.Date("2022-10-01"), linetype = "dotted") +
  facet_wrap(~ type)

Inflation Facet

English

Code
energy %>%
  filter(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02",
                         "CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST",
                         "CP0722MI15EA20M086NEST", "CUSR0000SETB")) %>%
  select(date, variable, value) %>%
  group_by(variable) %>%
  arrange(date) %>%
  mutate(value = value/lag(value, 12) - 1) %>%
  filter(date >= as.Date("2021-01-01")) %>%
  mutate(country = case_when(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02", "CUSR0000SETB") ~ "US (CPI)",
                             variable %in% c("CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST", "CP0722MI15EA20M086NEST") ~ "Euro area (HICP)"),
         type = case_when(variable %in% c("CUSR0000SEHF01", "CP0451MI15EA20M086NEST") ~ "Electricity",
                          variable %in% c("CUSR0000SEHF02", "CP0452MI15EA20M086NEST") ~ "Natural gas",
                          variable %in% c("CUSR0000SETB", "CP0722MI15EA20M086NEST") ~ "Fuel"),
         type = factor(type, levels = c("Natural gas", "Electricity", "Fuel"))) %>%
  na.omit %>%
  ggplot(.) + geom_line(aes(x = date, y = value, color = country)) + theme_minimal() +
  scale_x_date(breaks = seq.Date(from = as.Date("2021-03-01"), to = Sys.Date(), by = "6 months"),
               labels = scales::date_format("%b %Y")) + 
  scale_y_continuous(breaks = 0.01*seq(-60, 100, 5),
                     labels = scales::percent_format(accuracy = 1)) + 
  scale_color_manual(values = c("#003399", "#B22234")) +
  xlab("") + ylab("Inflation (%)") +
  theme(legend.position = "top",
        legend.title = element_blank(),
        axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
  geom_vline(xintercept = as.Date("2022-06-01"), linetype = "dotted") + 
  geom_vline(xintercept = as.Date("2022-10-01"), linetype = "dotted") +
  facet_wrap(~ type)

French

Code
Sys.setlocale("LC_TIME", "fr_CA.UTF-8")
# [1] "fr_CA.UTF-8"
Code
energy %>%
  filter(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02",
                         "CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST",
                         "CP0722MI15EA20M086NEST", "CUSR0000SETB")) %>%
  select(date, variable, value) %>%
  group_by(variable) %>%
  arrange(date) %>%
  mutate(value = value/lag(value, 12) - 1) %>%
  filter(date >= as.Date("2021-01-01")) %>%
  mutate(country = case_when(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02", "CUSR0000SETB") ~ "États-Unis (CPI)",
                             variable %in% c("CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST", "CP0722MI15EA20M086NEST") ~ "Zone euro (IPCH)"),
         type = case_when(variable %in% c("CUSR0000SEHF01", "CP0451MI15EA20M086NEST") ~ "Électricité",
                          variable %in% c("CUSR0000SEHF02", "CP0452MI15EA20M086NEST") ~ "Gaz naturel",
                          variable %in% c("CUSR0000SETB", "CP0722MI15EA20M086NEST") ~ "Carburants"),
         type = factor(type, levels = c("Gaz naturel", "Électricité", "Carburants")),
         country = factor(country, levels = c("Zone euro (IPCH)", "États-Unis (CPI)"))) %>%
  na.omit %>%
  ggplot(.) + geom_line(aes(x = date, y = value, color = country)) + theme_minimal() +
  scale_x_date(breaks = seq.Date(from = as.Date("2021-01-01"), to = Sys.Date(), by = "3 months"),
               labels = scales::date_format("%b %Y")) + 
  scale_y_continuous(breaks = 0.01*seq(-60, 100, 5),
                     labels = scales::percent_format(accuracy = 1)) + 
  scale_color_manual(values = c("#003399", "#B22234")) +
  xlab("") + ylab("Inflation sur un an (%)") +
  theme(legend.position = "top",
        legend.title = element_blank(),
        axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
  geom_vline(xintercept = as.Date("2022-06-01"), linetype = "dotted") + 
  geom_vline(xintercept = as.Date("2022-10-01"), linetype = "dotted") +
  facet_wrap(~ type)

Code
Sys.setlocale("LC_TIME", "en_CA.UTF-8")
# [1] "en_CA.UTF-8"

Price Index

Code
energy %>%
  filter(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02", "CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST")) %>%
  select(date, variable, value) %>%
  filter(date >= as.Date("2020-01-01")) %>%
  group_by(variable) %>%
  arrange(date) %>%
  mutate(value = 100*value/value[1]) %>%
  mutate(country = case_when(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02") ~ "United States (CPI)",
                             variable %in% c("CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST") ~ "Euro area (HICP)"),
         type = case_when(variable %in% c("CUSR0000SEHF01", "CP0451MI15EA20M086NEST") ~ "Electricity",
                          variable %in% c("CUSR0000SEHF02", "CP0452MI15EA20M086NEST") ~ "Natural gas")) %>%
  na.omit %>%
  ggplot(.) + geom_line(aes(x = date, y = value, color = country, linetype = type)) + theme_minimal() +
  scale_x_date(breaks = seq.Date(from = as.Date("2020-01-01"), to = Sys.Date(), by = "2 months"),
               labels = scales::date_format("%b %Y")) + 
  scale_y_continuous(breaks = seq(100, 300, 10)) + 
  scale_color_manual(values = c("#003399", "#B22234")) +
  xlab("") + ylab("Price Index (January 2020 = 100)") +
  theme(legend.position = c(0.3, 0.78),
        legend.title = element_blank(),
        axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))

Price Index Facet

Code
energy %>%
  filter(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02", "CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST")) %>%
  select(date, variable, value) %>%
  filter(date >= as.Date("2020-01-01")) %>%
  group_by(variable) %>%
  arrange(date) %>%
  mutate(value = 100*value/value[1]) %>%
  mutate(country = case_when(variable %in% c("CUSR0000SEHF01", "CUSR0000SEHF02") ~ "United States (CPI)",
                             variable %in% c("CP0451MI15EA20M086NEST", "CP0452MI15EA20M086NEST") ~ "Euro area (HICP)"),
         type = case_when(variable %in% c("CUSR0000SEHF01", "CP0451MI15EA20M086NEST") ~ "Electricity",
                          variable %in% c("CUSR0000SEHF02", "CP0452MI15EA20M086NEST") ~ "Natural gas")) %>%
  na.omit %>%
  ggplot(.) + geom_line(aes(x = date, y = value, color = country)) + theme_minimal() +
  scale_x_date(breaks = seq.Date(from = as.Date("2020-01-01"), to = Sys.Date(), by = "2 months"),
               labels = scales::date_format("%b %Y")) + 
  scale_y_continuous(breaks = seq(100, 300, 10)) + 
  scale_color_manual(values = c("#003399", "#B22234")) +
  xlab("") + ylab("Price Index (January 2020 = 100)") +
  theme(legend.position = c(0.3, 0.78),
        legend.title = element_blank(),
        axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
  facet_wrap(~ type)

Natural Gas prices

Linear

All

Code
energy %>%
  filter(variable %in% c("MHHNGSP", "PNGASEUUSDM")) %>%
  left_join(variable, by = "variable") %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, 5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 5), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("U.S. Dollars per Million Metric British Thermal Unit")

1990-

Linear

Code
energy %>%
  filter(variable %in% c("MHHNGSP", "PNGASEUUSDM")) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= as.Date("1990-01-01")) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, 5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 5), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("U.S. Dollars per Million Metric British Thermal Unit")

2004-

Code
energy %>%
  filter(variable %in% c("MHHNGSP", "PNGASEUUSDM")) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= as.Date("2004-01-01")) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, 5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 2), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("U.S. Dollars per Million Metric British Thermal Unit")

Last 10 years

Code
energy %>%
  filter(variable %in% c("MHHNGSP", "PNGASEUUSDM")) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= Sys.Date() - years(10)) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, 5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 1), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("U.S. Dollars per Million Metric British Thermal Unit")

Last 5 years

Code
energy %>%
  filter(variable %in% c("MHHNGSP", "PNGASEUUSDM")) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= Sys.Date() - years(5)) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, 5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 1), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("U.S. Dollars per Million Metric British Thermal Unit")

Energy Share

Code
energy %>%
  filter(variable %in% c("WTISPLC", "OILPRODWLD", "NYGDPMKTPCDWLD"),
         month(date) == 1) %>%
  spread(variable, value) %>%
  mutate(oil_share = 1000*OILPRODWLD*7.14/NYGDPMKTPCDWLD) %>%
  filter(!is.na(oil_share)) %>%
  ggplot + geom_line(aes(x = date, y = oil_share)) +
  labs(x = "", y = "Oil share") + theme_minimal() +
  scale_y_continuous(breaks = 0.01*seq(-20, 100, .1),
                     labels = percent_format(a = .1))

GASREGW, MICH

Linear

All

Code
energy %>%
  filter(variable %in% c("GASREGW", "MICH")) %>%
  left_join(variable, by = "variable") %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, .5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 5), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("Inflation Expectations (%), Gallon of Oil ($)")

1990-

Code
energy %>%
  filter(variable %in% c("GASREGW", "MICH")) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= as.Date("1990-01-01")) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, .5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 5), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("Inflation Expectations (%), Gallon of Oil ($)")

1995-

English

Code
energy %>%
  filter(variable %in% c("GASREGW", "MICH")) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= as.Date("1995-01-01")) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.25, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, .5)) + 
  scale_color_manual(values = viridis(2)[1:2]) +
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 2), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("Inflation Expectations (%), Gallon of Oil ($)")

Français

Code
energy %>%
  filter(variable %in% c("GASREGW", "MICH")) %>%
  left_join(variable, by = "variable") %>%
  mutate(Variable = case_when(variable == "GASREGW" ~ "Prix du pétrole à la pompe ($/gallon)",
                              variable == "MICH" ~ "Université du Michigan: Anticipations d'inflation (%)")) %>%
  filter(date >= as.Date("1990-01-01")) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.7, 0.1)) +
  scale_y_continuous(breaks = seq(0, 150, .5)) + 
  scale_color_manual(values = viridis(2)[2:1]) +
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 5), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("Université du Michigan: Anticipations d'inflation (%)\nPrix du pétrole à la pompe ($/gallon)")

2004-

Code
energy %>%
  filter(variable %in% c("GASREGW", "MICH")) %>%
  #add_row(variable = "MICH", date = as.Date("2023-05-01"), value = 4.2) %>%
  #add_row(variable = "MICH", date = as.Date("2023-06-01"), value = 3.3) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= as.Date("2004-01-01")) %>%
  arrange(desc(date)) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, .5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 2), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("Inflation Expectations (%), Gallon of Oil ($)")

Last 10 years

Code
energy %>%
  filter(variable %in% c("GASREGW", "MICH")) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= Sys.Date() - years(10)) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.5, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, .5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 1), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("Inflation Expectations (%), Gallon of Oil ($)")

Last 5 years

Code
energy %>%
  filter(variable %in% c("GASREGW", "MICH")) %>%
  left_join(variable, by = "variable") %>%
  filter(date >= Sys.Date() - years(5)) %>%
  ggplot() + geom_line(aes(x = date, y = value, color = Variable)) + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, .5)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 1), "-01-01")),
               labels = date_format("%Y")) +
  xlab("") + ylab("Inflation Expectations (%), Gallon of Oil ($)")

Oil

All

Linear

Code
plot_linear <- energy %>%
  filter(variable %in% c("WTISPLC")) %>%
  ggplot() + labs(x = "Observation Date", y = "Rate") + theme_minimal() +
  geom_line(aes(x = date, y = value)) +
  geom_rect(data = nber_recessions %>%
              filter(Peak > as.Date("1945-01-01")), 
            aes(xmin = Peak, xmax = Trough, ymin = 0, ymax = +Inf), 
            fill = 'grey', alpha = 0.5) +
  theme(legend.title = element_blank(),
        legend.position = c(0.8, 0.2)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 10), "-01-01")),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(0, 150, 25),
                labels = scales::dollar_format(accuracy = 1)) +
  xlab("") + ylab("Barrel Price")

plot_linear

Log

Code
plot_log <- plot_linear +
  scale_y_log10(breaks = c(1, 2, 3, 5, 8, 10, 20, 30, 50, 80, 100, 120, 150),
                labels = scales::dollar_format(accuracy = 1))

plot_log

Both

Code
ggpubr::ggarrange(plot_linear + ggtitle("Linear"), plot_log + ggtitle("Log") + ylab(""))

1955

Linear

Code
plot_linear <- energy %>%
  filter(variable %in% c("WTISPLC"),
         date >= as.Date("1955-01-01")) %>%
  ggplot() + labs(x = "Observation Date", y = "Rate") + theme_minimal() +
  geom_line(aes(x = date, y = value)) +
  geom_rect(data = nber_recessions %>%
              filter(Peak > as.Date("1955-01-01")), 
            aes(xmin = Peak, xmax = Trough, ymin = 0, ymax = +Inf), 
            fill = 'grey', alpha = 0.5) +
  theme(legend.title = element_blank(),
        legend.position = c(0.8, 0.2)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 10), "-01-01")),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(0, 150, 25),
                labels = scales::dollar_format(accuracy = 1)) +
  xlab("") + ylab("Barrel Price")

plot_linear

Log

Code
plot_log <- plot_linear +
  scale_y_log10(breaks = c(1, 2, 3, 5, 8, 10, 20, 30, 50, 80, 100, 120, 150),
                labels = scales::dollar_format(accuracy = 1))

plot_log

Both

Code
ggpubr::ggarrange(plot_linear + ggtitle("Linear"), plot_log + ggtitle("Log") + ylab(""))

1970-

Linear

Code
plot_linear <- energy %>%
  filter(variable %in% c("WTISPLC"),
         date >= as.Date("1970-01-01")) %>%
  ggplot() + labs(x = "Observation Date", y = "Rate") + theme_minimal() +
  geom_line(aes(x = date, y = value)) +
  geom_rect(data = nber_recessions %>%
              filter(Peak > as.Date("1970-01-01")), 
            aes(xmin = Peak, xmax = Trough, ymin = 0, ymax = +Inf), 
            fill = 'grey', alpha = 0.5) +
  theme(legend.title = element_blank(),
        legend.position = c(0.8, 0.2)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 10), "-01-01")),
               labels = date_format("%Y")) +
  scale_y_continuous(breaks = seq(0, 150, 25),
                labels = scales::dollar_format(accuracy = 1)) +
  xlab("") + ylab("Barrel Price")

plot_linear

Log

Code
plot_log <- plot_linear +
  scale_y_log10(breaks = c(1, 2, 3, 5, 8, 10, 20, 30, 50, 80, 100, 120, 150),
                labels = scales::dollar_format(accuracy = 1))

plot_log

Both

Code
ggpubr::ggarrange(plot_linear + ggtitle("Linear"), plot_log + ggtitle("Log") + ylab(""))

Oil, Real Oil

All

Linear

Code
plot_linear <- energy %>%
  filter(variable %in% c("CPIAUCSL", "WTISPLC")) %>%
  spread(variable, value) %>%
  transmute(date, WTISPLC,
            WTISPLC_real = CPIAUCSL[860]* WTISPLC / CPIAUCSL,) %>%
  gather(variable, value, -date) %>%
  mutate(Variable = case_when(variable == "WTISPLC" ~ "Oil Prices (WTI)",
                                   variable == "WTISPLC_real" ~ "Real Oil Prices (WTI)")) %>%
  select(variable, Variable, everything()) %>%
  ggplot() + labs(x = "Observation Date", y = "Rate") + theme_minimal() +
  geom_line(aes(x = date, y = value, color = Variable)) +
  geom_rect(data = nber_recessions %>%
              filter(Peak > as.Date("1928-01-01")), 
            aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf), 
            fill = 'grey', alpha = 0.5) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, 25),
                labels = scales::dollar_format(accuracy = 1)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 10), "-01-01")),
               labels = date_format("%Y"),
               limits = c(as.Date("1945-01-01"), Sys.Date())) +
  xlab("") + ylab("Barrel Price")

plot_linear

Log

Code
plot_log <- plot_linear +
  geom_rect(data = nber_recessions %>%
              filter(Peak > as.Date("1928-01-01")), 
            aes(xmin = Peak, xmax = Trough, ymin = 0, ymax = +Inf), 
            fill = 'grey', alpha = 0.5) +
  scale_y_log10(breaks = c(1, 2, 3, 5, 8, 10, 20, 30, 50, 80, 100, 120, 150),
                labels = scales::dollar_format(accuracy = 1))

plot_log

Both

Code
ggpubr::ggarrange(plot_linear + ggtitle("Linear"),
                  plot_log + ggtitle("Log") + ylab(""),
                  common.legend = T)

1970-

Linear

Code
plot_linear <- energy %>%
  filter(variable %in% c("CPIAUCSL", "WTISPLC")) %>%
  spread(variable, value) %>%
  transmute(date, WTISPLC,
            WTISPLC_real = CPIAUCSL[860]* WTISPLC / CPIAUCSL,) %>%
  gather(variable, value, -date) %>%
  mutate(Variable = case_when(variable == "WTISPLC" ~ "Oil Prices (WTI)",
                                   variable == "WTISPLC_real" ~ "Real Oil Prices (WTI)")) %>%
  select(variable, Variable, everything()) %>%
  filter(date >= as.Date("1970-01-01")) %>%
  ggplot() + labs(x = "Observation Date", y = "Rate") + theme_minimal() +
  geom_line(aes(x = date, y = value, color = Variable)) +
  geom_rect(data = nber_recessions %>%
              filter(Peak > as.Date("1928-01-01")), 
            aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf), 
            fill = 'grey', alpha = 0.5) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.9)) +
  scale_y_continuous(breaks = seq(0, 150, 25),
                labels = scales::dollar_format(accuracy = 1)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2100, 10), "-01-01")),
               labels = date_format("%Y"),
               limits = c(as.Date("1970-01-01"), Sys.Date())) +
  xlab("") + ylab("Barrel Price")

plot_linear

Log

Code
plot_log <- plot_linear +
  scale_y_log10(breaks = c(1, 2, 3, 5, 8, 10, 20, 30, 50, 80, 100, 120, 150),
                labels = scales::dollar_format(accuracy = 1))

plot_log

Both

Code
ggpubr::ggarrange(plot_linear + ggtitle("Linear"),
                  plot_log + ggtitle("Log") + ylab(""),
                  common.legend = T)