Browse Source

Plotly for interactive graphs

Not self-contained (easier to load and archive)
Small corrections
master
Maxime Wack 7 years ago
parent
commit
d0ba711e6e
1 changed files with 59 additions and 33 deletions
  1. +59
    -33
      cloture.Rmd

+ 59
- 33
cloture.Rmd View File

@@ -4,6 +4,7 @@ output:
html_document: html_document:
toc: true toc: true
toc_float: true toc_float: true
self_contained: false
--- ---


```{r init, echo = F, message = F} ```{r init, echo = F, message = F}
@@ -13,12 +14,13 @@ library(knitr)
library(tidyr) library(tidyr)
library(stringr) library(stringr)
library(dplyr) library(dplyr)
library(plotly)


opts_chunk$set(echo = F, opts_chunk$set(echo = F,
message = F, message = F,
warning = F, warning = F,
fig.width = 12,
fig.height = 7)
fig.width = 10,
fig.height = 6)


options(DT.options = list(paging = F, options(DT.options = list(paging = F,
searching = F, searching = F,
@@ -91,21 +93,24 @@ rum %>%
rum %>% rum %>%
count(annee_sortie, mois_sortie) %>% count(annee_sortie, mois_sortie) %>%
ungroup %>% ungroup %>%
mutate(annee_sortie = annee_sortie %>% factor) %>%


ggplot +
ggplot(
aes(x = mois_sortie, aes(x = mois_sortie,
y = n, y = n,
color = annee_sortie %>% factor,
shape = annee_sortie %>% factor) +
color = annee_sortie,
shape = annee_sortie)) +
scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = "RUM") + title = "RUM") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1), theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.title = element_blank(), legend.title = element_blank(),
plot.title = element_text(hjust = 0))
plot.title = element_text(hjust = 0)) -> p
ggplotly(p, tooltip = c("x", "y", "colour"))
``` ```


## Nombre de RSS transmis par mois pour les 3 dernières années ## Nombre de RSS transmis par mois pour les 3 dernières années
@@ -131,21 +136,24 @@ rss %>%
rss %>% rss %>%
count(annee_sortie, mois_sortie) %>% count(annee_sortie, mois_sortie) %>%
ungroup %>% ungroup %>%
mutate(annee_sortie = annee_sortie %>% factor) %>%


ggplot +
ggplot(
aes(x = mois_sortie, aes(x = mois_sortie,
y = n, y = n,
color = annee_sortie %>% factor,
shape = annee_sortie %>% factor) +
color = annee_sortie,
shape = annee_sortie)) +
scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = "RSS") + title = "RSS") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1), theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.title = element_blank(), legend.title = element_blank(),
plot.title = element_text(hjust = 0))
plot.title = element_text(hjust = 0)) -> p
ggplotly(p, tooltip = c("x", "y", "colour"))
``` ```


### Nombre de RSS de 1 jour et plus transmis par mois pour les 3 dernières années ### Nombre de RSS de 1 jour et plus transmis par mois pour les 3 dernières années
@@ -172,21 +180,24 @@ rss %>%
filter(duree_rss >= 1) %>% filter(duree_rss >= 1) %>%
count(annee_sortie, mois_sortie) %>% count(annee_sortie, mois_sortie) %>%
ungroup %>% ungroup %>%
mutate(annee_sortie = annee_sortie %>% factor) %>%


ggplot +
ggplot(
aes(x = mois_sortie, aes(x = mois_sortie,
y = n, y = n,
color = annee_sortie %>% factor,
shape = annee_sortie %>% factor) +
color = annee_sortie,
shape = annee_sortie)) +
scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = "RSS de 1 jour et +") + title = "RSS de 1 jour et +") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1), theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.title = element_blank(), legend.title = element_blank(),
plot.title = element_text(hjust = 0))
plot.title = element_text(hjust = 0)) -> p
ggplotly(p, tooltip = c("x", "y", "colour"))
``` ```


### Nombre de RSS de 0 jour (hors séances) transmis par mois pour les 3 dernières années ### Nombre de RSS de 0 jour (hors séances) transmis par mois pour les 3 dernières années
@@ -215,21 +226,24 @@ rss %>%
filter(duree_rss == 0, cmd != 28) %>% filter(duree_rss == 0, cmd != 28) %>%
count(annee_sortie, mois_sortie) %>% count(annee_sortie, mois_sortie) %>%
ungroup %>% ungroup %>%
mutate(annee_sortie = annee_sortie %>% factor) %>%


ggplot +
ggplot(
aes(x = mois_sortie, aes(x = mois_sortie,
y = n, y = n,
color = annee_sortie %>% factor,
shape = annee_sortie %>% factor) +
color = annee_sortie,
shape = annee_sortie)) +
scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = "RSS de 0 jour, hors séances") + title = "RSS de 0 jour, hors séances") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1), theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.title = element_blank(), legend.title = element_blank(),
plot.title = element_text(hjust = 0))
plot.title = element_text(hjust = 0)) -> p
ggplotly(p, tooltip = c("x", "y", "colour"))
``` ```


### Nombre de RSS de séance transmis par mois pour les 3 dernières années ### Nombre de RSS de séance transmis par mois pour les 3 dernières années
@@ -256,21 +270,24 @@ rss %>%
filter(duree_rss == 0, cmd == 28) %>% filter(duree_rss == 0, cmd == 28) %>%
count(annee_sortie, mois_sortie) %>% count(annee_sortie, mois_sortie) %>%
ungroup %>% ungroup %>%
mutate(annee_sortie = annee_sortie %>% factor) %>%


ggplot +
ggplot(
aes(x = mois_sortie, aes(x = mois_sortie,
y = n, y = n,
color = annee_sortie %>% factor,
shape = annee_sortie %>% factor) +
color = annee_sortie,
shape = annee_sortie)) +
scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = "RSS de séances") + title = "RSS de séances") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1), theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.title = element_blank(), legend.title = element_blank(),
plot.title = element_text(hjust = 0))
plot.title = element_text(hjust = 0)) -> p
ggplotly(p, tooltip = c("x", "y", "colour"))
``` ```


## Nombre de RUM transmis par pôle pour les 3 dernières années ## Nombre de RUM transmis par pôle pour les 3 dernières années
@@ -280,6 +297,7 @@ rum %>%
filter(! is.na(pole_libelle)) %>% filter(! is.na(pole_libelle)) %>%
count(pole_libelle, annee_sortie) %>% count(pole_libelle, annee_sortie) %>%
ungroup %>% ungroup %>%
mutate(pole_libelle = pole_libelle %>% str_replace("\xc9", "É")) %>%
spread(annee_sortie, n) %>% spread(annee_sortie, n) %>%
bind_rows(select(., -pole_libelle) %>% bind_rows(select(., -pole_libelle) %>%
summarise_each(funs(sum(., na.rm = T))) %>% summarise_each(funs(sum(., na.rm = T))) %>%
@@ -296,11 +314,12 @@ rum %>%
filter(! is.na(pole_libelle)) %>% filter(! is.na(pole_libelle)) %>%
count(pole_libelle, annee_sortie) %>% count(pole_libelle, annee_sortie) %>%
ungroup %>% ungroup %>%
mutate(pole_libelle = pole_libelle %>% str_replace("\xc9", "É")) %>%


ggplot +
ggplot(
aes(x = annee_sortie, aes(x = annee_sortie,
y = n, y = n,
color = pole_libelle) +
color = pole_libelle)) +
scale_x_continuous(breaks = (annee - 2):annee) + scale_x_continuous(breaks = (annee - 2):annee) +
facet_wrap(~ pole_libelle, scales = "free") + facet_wrap(~ pole_libelle, scales = "free") +
geom_point() + geom_point() +
@@ -308,6 +327,7 @@ rum %>%
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = "RUM par pôle") + title = "RUM par pôle") +
theme_bw() +
theme(legend.position = "none", theme(legend.position = "none",
plot.title = element_text(hjust = 0)) plot.title = element_text(hjust = 0))
``` ```
@@ -336,16 +356,18 @@ exhau %>%
mutate(rss_prod = rss + manq, mutate(rss_prod = rss + manq,
exh = 100 * rss / rss_prod) %>% exh = 100 * rss / rss_prod) %>%


ggplot +
ggplot(
aes(x = mois, aes(x = mois,
y = exh) +
y = exh)) +
geom_point() + geom_point() +
geom_line() + geom_line() +
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = NULL) + title = NULL) +
scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) -> p
ggplotly(p)


``` ```


@@ -364,18 +386,20 @@ rss %>%
mutate(n = 100 * (n.x - n.y) / n.x, mutate(n = 100 * (n.x - n.y) / n.x,
n = ifelse(is.na(n), 100, n)) %>% n = ifelse(is.na(n), 100, n)) %>%


ggplot +
ggplot(
aes(x = mois_sortie, aes(x = mois_sortie,
y = n) +
y = n)) +
scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = NULL) + title = NULL) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1), theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.title = element_blank(), legend.title = element_blank(),
plot.title = element_text(hjust = 0))
plot.title = element_text(hjust = 0)) -> p
ggplotly(p)
``` ```


### Nombre de RSS manquants pour la clôture actuelle selon le mois de sortie du RSS ### Nombre de RSS manquants pour la clôture actuelle selon le mois de sortie du RSS
@@ -384,18 +408,20 @@ gam %>%
count(mois_sortie) %>% count(mois_sortie) %>%
full_join(data.frame(mois_sortie = setdiff(1:mois, .$mois_sortie), n = rep(0, length(setdiff(1:mois, .$mois_sortie))))) %>% full_join(data.frame(mois_sortie = setdiff(1:mois, .$mois_sortie), n = rep(0, length(setdiff(1:mois, .$mois_sortie))))) %>%


ggplot +
ggplot(
aes(x = mois_sortie, aes(x = mois_sortie,
y = n) +
y = n)) +
scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
labs(x = NULL, labs(x = NULL,
y = NULL, y = NULL,
title = NULL) + title = NULL) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1), theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.title = element_blank(), legend.title = element_blank(),
plot.title = element_text(hjust = 0))
plot.title = element_text(hjust = 0)) -> p
ggplotly(p)
``` ```


## Exhaustivité par pôle et par service ## Exhaustivité par pôle et par service


Loading…
Cancel
Save