# ---- 1. Données Figure 1a et 1b telles que publiées par l'Insee (déflaté IPC) ----
fig1a <- ip2117$data[[2]] %>%
rename(annee = 1, D1 = 2, D5 = 3, D9 = 4) %>%
mutate(annee = as.numeric(annee))
fig1b <- ip2117$data[[3]] %>%
rename(annee = 1, D1 = 2, D5 = 3, D9 = 4) %>%
mutate(annee = as.numeric(annee))
# ---- 2. Ratio IPC/IPCH, rebasé à 1 en 2008 (année de référence des figures) ----
prix <- `IPCH-IPC-2025-ensemble-A` %>%
mutate(annee = as.numeric(format(date, "%Y"))) %>%
select(annee, INDICATEUR, OBS_VALUE) %>%
pivot_wider(names_from = INDICATEUR, values_from = OBS_VALUE) %>%
mutate(ratio = IPC / IPCH) %>%
mutate(ratio_rebase = ratio / ratio[annee == 2008])
# ---- 3. Reconversion IPC -> IPCH : niveau de vie déflaté IPCH = niveau de vie déflaté IPC x (IPC/IPCH), rebasé 2008 = 100 ----
deflate_ipch <- function(df) {
df %>%
left_join(prix %>% select(annee, ratio_rebase), by = "annee") %>%
mutate(across(c(D1, D5, D9), ~ .x * ratio_rebase)) %>%
select(-ratio_rebase)
}
fig1a_ipch <- deflate_ipch(fig1a)
fig1b_ipch <- deflate_ipch(fig1b)
# ---- 4. Mise en forme longue ----
mise_en_forme <- function(df, suffixe) {
df %>%
pivot_longer(cols = c(D1, D5, D9), names_to = "decile", values_to = "valeur") %>%
mutate(
decile = factor(decile, levels = c("D5", "D9", "D1")),
label = paste0(decile, " ", suffixe)
)
}
long_1a <- mise_en_forme(fig1a_ipch, "avant redistribution")
long_1b <- mise_en_forme(fig1b_ipch, "après redistribution")
couleurs <- c("D5" = "#E8737A", "D9" = "#1B3F8B", "D1" = "#B8860B")
# ---- 5. Fonction de graphique générique (même habillage que la réplique IPC) ----
graphe_niveau_vie <- function(data, labels_df, titre) {
ggplot(data, aes(x = annee, y = valeur, color = decile, group = decile)) +
geom_hline(yintercept = 100, color = "black", linewidth = 0.5) +
geom_line(linewidth = 1.1) +
geom_text(
data = labels_df,
aes(x = annee, y = valeur, label = label, color = decile),
fontface = "bold", size = 5.2, hjust = 0, show.legend = FALSE
) +
scale_color_manual(values = couleurs) +
scale_x_continuous(
breaks = seq(1996, 2024, by = 4),
limits = c(1996, 2025),
expand = expansion(mult = c(0.01, 0.02))
) +
scale_y_continuous(
breaks = seq(70, 115, by = 5),
limits = c(70, 115),
expand = c(0, 0)
) +
labs(
x = NULL, y = NULL,
title = titre,
subtitle = "indice base 100 en 2008, en euros constants (déflaté IPCH)"
) +
theme_minimal(base_size = 15) +
theme(
legend.position = "none",
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(color = "grey85", linewidth = 0.4),
axis.text = element_text(color = "grey20", size = 15),
axis.text.x = element_text(margin = margin(t = 6)),
plot.title = element_text(face = "bold", size = 19, color = "grey30", margin = margin(b = 10)),
plot.subtitle = element_text(size = 14, color = "grey30", margin = margin(b = 12)),
plot.background = element_rect(fill = "#F5F5F3", color = NA),
panel.background = element_rect(fill = "#F5F5F3", color = NA),
plot.margin = margin(15, 20, 10, 10)
)
}
# ---- 6. Étiquettes sur les courbes (mêmes positions que la version IPC ; les courbes bougent peu) ----
labels_1a <- tribble(
~annee, ~valeur, ~label, ~decile,
1997.2, 103.5, "D5 avant redistribution", "D5",
2013, 100.5, "D9 avant redistribution", "D9",
2004.5, 87.3, "D1 avant redistribution", "D1"
)
labels_1b <- tribble(
~annee, ~valeur, ~label, ~decile,
2007.3, 106.3, "D5 après redistribution", "D5",
2010.3, 91.3, "D9 après redistribution", "D9",
2003.8, 81.3, "D1 après redistribution", "D1"
)
p_1a <- graphe_niveau_vie(long_1a, labels_1a, "a. Avant redistribution")
p_1b <- graphe_niveau_vie(long_1b, labels_1b, "b. Après redistribution")
p_combine <- gridExtra::arrangeGrob(p_1a, p_1b, ncol = 2) # s'affiche automatiquement en session interactive
ggsave("~/Downloads/ip2117_IPCH.png", p_combine,
width = 16, height = 8, dpi = 200, bg = "#F5F5F3")