Inflation

# please download the Github version
# devtools::install_github("InseeFr/R-Insee-Data")

library(lubridate)
library(insee)
library(ggplot2)
library(dplyr)
library(magrittr)

df_idbank_list_selected =
  get_idbank_list("IPC-2015") %>% #Inflation dataset
  filter(FREQ == "M") %>% # monthly
  filter(str_detect(COICOP2016, "^[0-9]{2}$")) %>% # coicop aggregation level
  filter(NATURE == "INDICE") %>% # index
  filter(MENAGES_IPC == "ENSEMBLE") %>% # all kinds of household
  filter(REF_AREA == "FE") %>% # all France including overseas departements
  add_insee_title()

list_idbank = df_idbank_list_selected %>% pull(idbank)

data = 
  get_insee_idbank(list_idbank, startPeriod = "2015-01") %>% 
  add_insee_metadata()

data_plot = data %>%
  mutate(month = month(DATE)) %>%
  arrange(DATE) %>%
  filter(COICOP2016 != "12") %>% 
  group_by(COICOP2016_label_en, month) %>%
  mutate(growth = 100 * (OBS_VALUE / dplyr::lag(OBS_VALUE) - 1))

ggplot(data_plot, aes(x = DATE, y = growth)) +
  geom_col() +
  facet_wrap(~COICOP2016_label_en, scales = "free", labeller = label_wrap_gen(22)) +
  ggtitle("French inflation, by product category, year-on-year") +
  labs(subtitle = sprintf("Last updated : %s", data_plot$TIME_PERIOD[nrow(data_plot)]))