From d0ba711e6e6372850d99a96a2e33ed60ad23a4a2 Mon Sep 17 00:00:00 2001 From: Maxime Wack Date: Tue, 5 Jul 2016 16:42:32 +0200 Subject: [PATCH] Plotly for interactive graphs Not self-contained (easier to load and archive) Small corrections --- cloture.Rmd | 92 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/cloture.Rmd b/cloture.Rmd index 4951009..cdb83ac 100644 --- a/cloture.Rmd +++ b/cloture.Rmd @@ -4,6 +4,7 @@ output: html_document: toc: true toc_float: true + self_contained: false --- ```{r init, echo = F, message = F} @@ -13,12 +14,13 @@ library(knitr) library(tidyr) library(stringr) library(dplyr) +library(plotly) opts_chunk$set(echo = F, message = F, warning = F, - fig.width = 12, - fig.height = 7) + fig.width = 10, + fig.height = 6) options(DT.options = list(paging = F, searching = F, @@ -91,21 +93,24 @@ rum %>% rum %>% count(annee_sortie, mois_sortie) %>% ungroup %>% + mutate(annee_sortie = annee_sortie %>% factor) %>% - ggplot + + ggplot( aes(x = mois_sortie, 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)) + geom_line() + geom_point() + labs(x = NULL, y = NULL, title = "RUM") + + theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1), 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 @@ -131,21 +136,24 @@ rss %>% rss %>% count(annee_sortie, mois_sortie) %>% ungroup %>% + mutate(annee_sortie = annee_sortie %>% factor) %>% - ggplot + + ggplot( aes(x = mois_sortie, 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)) + geom_line() + geom_point() + labs(x = NULL, y = NULL, title = "RSS") + + theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1), 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 @@ -172,21 +180,24 @@ rss %>% filter(duree_rss >= 1) %>% count(annee_sortie, mois_sortie) %>% ungroup %>% + mutate(annee_sortie = annee_sortie %>% factor) %>% - ggplot + + ggplot( aes(x = mois_sortie, 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)) + geom_line() + geom_point() + labs(x = NULL, y = NULL, title = "RSS de 1 jour et +") + + theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1), 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 @@ -215,21 +226,24 @@ rss %>% filter(duree_rss == 0, cmd != 28) %>% count(annee_sortie, mois_sortie) %>% ungroup %>% + mutate(annee_sortie = annee_sortie %>% factor) %>% - ggplot + + ggplot( aes(x = mois_sortie, 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)) + geom_line() + geom_point() + labs(x = NULL, y = NULL, title = "RSS de 0 jour, hors séances") + + theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1), 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 @@ -256,21 +270,24 @@ rss %>% filter(duree_rss == 0, cmd == 28) %>% count(annee_sortie, mois_sortie) %>% ungroup %>% + mutate(annee_sortie = annee_sortie %>% factor) %>% - ggplot + + ggplot( aes(x = mois_sortie, 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)) + geom_line() + geom_point() + labs(x = NULL, y = NULL, title = "RSS de séances") + + theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1), 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 @@ -280,6 +297,7 @@ rum %>% filter(! is.na(pole_libelle)) %>% count(pole_libelle, annee_sortie) %>% ungroup %>% + mutate(pole_libelle = pole_libelle %>% str_replace("\xc9", "É")) %>% spread(annee_sortie, n) %>% bind_rows(select(., -pole_libelle) %>% summarise_each(funs(sum(., na.rm = T))) %>% @@ -296,11 +314,12 @@ rum %>% filter(! is.na(pole_libelle)) %>% count(pole_libelle, annee_sortie) %>% ungroup %>% + mutate(pole_libelle = pole_libelle %>% str_replace("\xc9", "É")) %>% - ggplot + + ggplot( aes(x = annee_sortie, y = n, - color = pole_libelle) + + color = pole_libelle)) + scale_x_continuous(breaks = (annee - 2):annee) + facet_wrap(~ pole_libelle, scales = "free") + geom_point() + @@ -308,6 +327,7 @@ rum %>% labs(x = NULL, y = NULL, title = "RUM par pôle") + + theme_bw() + theme(legend.position = "none", plot.title = element_text(hjust = 0)) ``` @@ -336,16 +356,18 @@ exhau %>% mutate(rss_prod = rss + manq, exh = 100 * rss / rss_prod) %>% - ggplot + + ggplot( aes(x = mois, - y = exh) + + y = exh)) + geom_point() + geom_line() + labs(x = NULL, y = NULL, title = NULL) + 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, n = ifelse(is.na(n), 100, n)) %>% - ggplot + + ggplot( aes(x = mois_sortie, - y = n) + + y = n)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + geom_line() + geom_point() + labs(x = NULL, y = NULL, title = NULL) + + theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1), 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 @@ -384,18 +408,20 @@ gam %>% count(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, - y = n) + + y = n)) + scale_x_discrete(limits = mois_label, expand = c(.05, 0)) + geom_line() + geom_point() + labs(x = NULL, y = NULL, title = NULL) + + theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1), 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