-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfigure1.R
More file actions
67 lines (55 loc) · 2.43 KB
/
Copy pathfigure1.R
File metadata and controls
67 lines (55 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
library(tidyverse)
library(readxl)
library(curl)
library(scales)
# ig_d("insee", "t_pib_vol", "deflateur-P3M-P51M-1999")
# https://fgeerolf.com/data/insee/t_pib_vol.html
temp <- tempfile()
curl_download("https://www.insee.fr/fr/statistiques/fichier/8196636/t_pib_vol.xls",
destfile = temp,
quiet = F)
t_pib_vol <- read_excel(temp, skip = 7, sheet = 2) %>%
rename(TIME_PERIOD = ...1) %>%
mutate(date = zoo::as.yearqtr(TIME_PERIOD, format = "%YT%q")) %>%
select(-TIME_PERIOD) %>%
filter(!is.na(date)) %>%
gather(variable, value, -date) %>%
filter(!is.na(value))
curl_download("https://www.insee.fr/fr/statistiques/fichier/8182876/t_pib_val.xls",
destfile = temp,
quiet = F)
# https://www.insee.fr/fr/statistiques/fichier/8196636/t_pib_vol.xls
# https://www.insee.fr/fr/statistiques/fichier/8182876/t_pib_vol.xls
t_pib_val <- read_excel(temp, skip = 7, sheet = 2) %>%
rename(TIME_PERIOD = ...1) %>%
mutate(date = zoo::as.yearqtr(TIME_PERIOD, format = "%YT%q")) %>%
select(-TIME_PERIOD) %>%
filter(!is.na(date)) %>%
gather(variable, value, -date) %>%
filter(!is.na(value))
t_pib_vol %>%
filter(variable %in% c("P3M", "P51M")) %>%
rename(vol = value) %>%
left_join(t_pib_val, by = c("date", "variable")) %>%
rename(val = value) %>%
mutate(deflateur = val/vol,
date = zoo::as.Date(date)) %>%
filter(date >= as.Date("1999-01-01"),
date <= as.Date("2024-01-01")) %>%
group_by(variable) %>%
arrange(date) %>%
mutate(deflateur = 100*deflateur/deflateur[1]) %>%
mutate(Variable = case_when(variable == "P3M" ~ "Déflateur de la consommation des ménages",
variable == "P51M" ~ "Déflateur de l'investissement des ménages")) %>%
ggplot + theme_minimal() + ylab("") + xlab("") +
geom_line(aes(x = date, y = deflateur, color = Variable)) +
theme(legend.title = element_blank(),
legend.position = c(0.3, 0.9)) +
scale_x_date(breaks = seq(1999, 2100, 5) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%Y")) +
scale_y_log10(breaks = seq(0, 1000, 10)) +
geom_label(data = . %>% filter(date == max(date)),
aes(x = date, y = deflateur, color = Variable, label = round(deflateur, 1))) +
labs(caption = "Source: Insee, calculs de l'auteur")
ggsave("figure1.png", width = 1.25*6, height = 1.25*3.375, bg = "white", dpi = 150)
ggsave("figure1.pdf", width = 1.25*6, height = 1.25*3.375, dpi = 150)