From 767d057f6ef98db08b72a4d251e77b31321c6b8e Mon Sep 17 00:00:00 2001 From: Valerie COGNAT Date: Wed, 22 Jul 2020 17:05:06 +0200 Subject: [PATCH] update lib --- module3/exo3/exercice_fr.Rmd | 30 +- module3/exo3/exercice_fr.html | 1887 ++++++++++++++++- .../time_series_covid19_confirmed_global.csv | 2 +- 3 files changed, 1898 insertions(+), 21 deletions(-) diff --git a/module3/exo3/exercice_fr.Rmd b/module3/exo3/exercice_fr.Rmd index 31c4362..028be48 100644 --- a/module3/exo3/exercice_fr.Rmd +++ b/module3/exo3/exercice_fr.Rmd @@ -12,18 +12,14 @@ knitr::opts_chunk$set(echo = TRUE) ```{r libraries, echo=FALSE, warning=FALSE, message=FALSE} -library(plyr) # help for data manipulation -library(dplyr) # help splitting, applying and combining data library(data.table) # extension to data.frame format, optimized for huge datasets -library(ggplot2) # The grammar of graphics, it improves the quality and aesthetic of your graphs -library(DT) +library(ggplot2) # for graphics library(plotly) -library(RColorBrewer) # package with pre-defined color palette ``` ## Récupération des données -Le fichier est téléchargé à partir de l'url puis lu via la fonction fread pour avoir un objet data.table. Le nom des colonnes est vérifié pour remplacer les caractères spéciaux par des ".". +Le fichier est téléchargé à partir de l'url [https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv](https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv) puis lu via la fonction fread pour avoir un objet de type data.table afin de faire facilement des graphiques avec ggplot2. Le nom des colonnes est vérifié pour remplacer les caractères spéciaux par des ".". ```{r data_dwld} url <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv" @@ -43,7 +39,7 @@ On commence par réannoter les pays pour mieux extraire ceux d'intérêts : - la france hors DOM-TOM est renommée France Metropolitaine - les colonies des pays bas sont renommées Netherlands, colonies -```{r} +```{r modify_country} ## change China to China, Hong Kong for Hong Kong covid_data[covid_data$Country.Region == "China" & covid_data$Province.State == "Hong Kong", ]$Country.Region <- "China, Hong-Kong" @@ -60,7 +56,7 @@ covid_data[covid_data$Country.Region == "United Kingdom" & covid_data$Province.S ### Creation d'un sous jeu de données pour analyse des pays d'intérêts Création d'un sous jeu de données avec les pays d'intérêts. -```{r} +```{r select_country} ## Filter only countries of interest covid.subset <- filter(covid_data, Country.Region %in% c("Belgium","China","China, Hong-Kong", "France","Germany","Iran","Italy", "Japan","Korea, South","Netherlands","Portugal","Spain", "United Kingdom", "US")) ``` @@ -72,7 +68,7 @@ Ce sera plus facile et rapide pour l'utilisation de ggplot2 d'avoir tous les com Pour cela nous utilisons fonction melt. -```{r} +```{r table_melt} covid.subset <- melt(covid.subset , id.vars = c("Province.State", "Country.Region", "Lat", "Long"), variable.name = "Date", @@ -85,7 +81,7 @@ covid.subset$Country.Region <- as.factor(covid.subset$Country.Region) ### Fusion des lignes pour un même pays Afin de n'avoir qu'une valeur par pays, nous fusionnons les lignes -```{r} +```{r sum_cases} covid.byCountry <- covid.subset[, list(Case_number=sum(Case_number)),by=c("Country.Region","Date")] ``` @@ -93,8 +89,8 @@ covid.byCountry <- covid.subset[, list(Case_number=sum(Case_number)),by=c("Count Représentation du nombre de cas cumulés par jour par pays. -```{r plot, echo=FALSE, fig.height=15, fig.width=12} -ggplot(covid.byCountry, aes(x = as.Date(Date), y = Case_number, group = Country.Region)) + +```{r plot, echo=FALSE, warning=FALSE, fig.height=12, fig.width=10} +p <- ggplot(covid.byCountry, aes(x = as.Date(Date), y = Case_number, group = Country.Region)) + geom_line(aes(color = Country.Region), size=1) + scale_color_manual(values = c("#00008B","#33a02c","#e31a1c","#8470FF","#FF7F24","#7A378B","#00688B","#FFF68F","#FF82AB","#5C5C5C","#87CEEB","#D9D9D9","#8B5A00","#9ACD32","#8EE5EE","#20B2AA","#FFF0F5","#FFFF00","#FFFFFF")) + scale_x_date(date_breaks = 'week') + @@ -104,12 +100,13 @@ ggplot(covid.byCountry, aes(x = as.Date(Date), y = Case_number, group = Country. ggtitle("Number of Covid Cases by Country") + xlab("Date") + ylab("Number of cases") + labs(color = "Country") - +#p +ggplotly(p) ``` Reproduction du graphique en log10 : -```{r plot_log, echo=FALSE, fig.height=15, fig.width=12} -ggplot(covid.byCountry, aes(x = as.Date(Date), y = Case_number, group = Country.Region)) + +```{r plot_log, echo=FALSE, warning=FALSE, fig.height=12, fig.width=10} +p <- ggplot(covid.byCountry, aes(x = as.Date(Date), y = Case_number, group = Country.Region)) + geom_line(aes(color = Country.Region), size = 1) + scale_color_manual(values = c("#00008B","#33a02c","#e31a1c","#8470FF","#FF7F24","#7A378B","#00688B","#FFF68F","#FF82AB","#5C5C5C","#87CEEB","#D9D9D9","#8B5A00","#9ACD32","#8EE5EE","#20B2AA","#FFF0F5","#FFFF00","#FFFFFF")) + scale_x_date(date_breaks = 'week') + @@ -121,5 +118,6 @@ ggplot(covid.byCountry, aes(x = as.Date(Date), y = Case_number, group = Country. xlab("Date") + ylab("Number of cases (log10)") + labs(color = "Country") - +#p +ggplotly(p) ``` diff --git a/module3/exo3/exercice_fr.html b/module3/exo3/exercice_fr.html index 7633e3b..beb8207 100644 --- a/module3/exo3/exercice_fr.html +++ b/module3/exo3/exercice_fr.html @@ -208,6 +208,1884 @@ color: #d14; } + + + + + + +