Skip to content

Instantly share code, notes, and snippets.

@SimonCoulombe
Created February 9, 2021 18:42
Show Gist options
  • Save SimonCoulombe/048973dfe0bb667f6563656fff0c2ffd to your computer and use it in GitHub Desktop.
Save SimonCoulombe/048973dfe0bb667f6563656fff0c2ffd to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggtext)
library(patchwork)
test <- read_csv(
paste0("https://www.donneesquebec.ca/recherche/dataset/",
"97fb0d09-d653-4365-be7e-a0e5e95c7641/resource/",
"eabc1984-5a0f-48f6-9f5c-bb96903df1a2/download/",
"stationnement-palais-des-congres-mtl.csv")
test2 <- test %>%
mutate(date = as.Date(Date_Extraction)) %>%
group_by(date) %>%
summarise(max_utilise = max(Nb_Espaces_Utilise))
test2_couvrefeu <- test %>%
filter(lubridate::hour(Date_Extraction)>=21 | lubridate::hour(Date_Extraction) <= 4 ) %>%
mutate(date = as.Date(Date_Extraction)) %>%
group_by(date) %>%
summarise(max_utilise = max(Nb_Espaces_Utilise))
capacite_label = tibble(
max_utilise = max(test$Capacite)-15,
date = max(test2$date- 15),
label = "Capacité",
color = "#D50A0A"
)
p1 <- test2 %>%
ggplot(aes(x= date, y = max_utilise)) +
geom_hline(yintercept = 285, color = "red", size =1) +
geom_col(width = 1)+
scale_y_continuous( expand = expansion(mult = c(0, 0.05)))+
scale_x_date(labels = scales::date_format("%b-%Y")) +
ggtext::geom_richtext(
data = capacite_label,
aes(x = date, y = max_utilise, color = color, label = label ),
fill = "white", label.color = NA, # remove background and outline
label.padding = grid::unit(rep(0,4), "pt"), # remove padding
family = "Chivo", hjust =1, fontface = "bold",
size = 8
) +
theme_bw() +
scale_color_identity() +
labs(
title = "Utilisation des stationnements du palais des \ncongrès de Montréal",
x = "date",
y = "Utilisation maximale quotidienne"#,
#caption = "@coulsim, source: https://www.donneesquebec.ca/recherche/dataset/achalandage-des-stationnements"
)
p2 <- test2_couvrefeu %>%
ggplot(aes(x= date, y = max_utilise)) +
geom_hline(yintercept = 285, color = "red", size =1) +
geom_col(width = 1)+
scale_y_continuous( expand = expansion(mult = c(0, 0.05)))+
scale_x_date(labels = scales::date_format("%b-%Y")) +
ggtext::geom_richtext(
data = capacite_label,
aes(x = date, y = max_utilise, color = color, label = label ),
fill = "white", label.color = NA, # remove background and outline
label.padding = grid::unit(rep(0,4), "pt"), # remove padding
family = "Chivo", hjust =1, fontface = "bold",
size = 8
) +
theme_bw() +
scale_color_identity() +
labs(
title = "Utilisation des stationnements du palais des \ncongrès de Montréal entre 21h et 4h",
x = "date",
y = "Utilisation maximale entre 21h et 4h",
caption = "@coulsim, source: https://www.donneesquebec.ca/recherche/dataset/achalandage-des-stationnements"
)
p1| p2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment