diff --git a/module3/exo3/exercice_en.Rmd b/module3/exo3/exercice_en.Rmd index 13b258ddd0da29bc3bf08c64b6a1db742f6d5409..c8ff18b7559d8e7337f7dd924041ba220c6c8693 100644 --- a/module3/exo3/exercice_en.Rmd +++ b/module3/exo3/exercice_en.Rmd @@ -1,33 +1,79 @@ --- -title: "Your title" -author: "Your name" -date: "Today's date" -output: html_document +title: "Subject 2: Purchasing power of English workers from the 16th to the 19th century" +author: "Oussama Oulkaid" +date: "November 28, 2021" +output: + pdf_document: default + html_document: + df_print: paged --- - ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) +options(warn = -1) ``` -## Some explanations +## Preamble -This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, see . +Ceci est un document R markdown que vous pouvez aisément exporter au format HTML, PDF, et MS Word. Pour plus de détails sur R Markdown consultez . -When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows: +Lorsque vous cliquerez sur le bouton **Knit** ce document sera compilé afin de ré-exécuter le code R et d'inclure les résultats dans un document final. Comme nous vous l'avons montré dans la vidéo, on inclue du code R de la façon suivante: -```{r cars} -summary(cars) +We will need to use the following libraries: +```{r, results=FALSE, message=FALSE} +# The environment +library(tidyverse) +library(ggplot2) +library(reshape2) +library(Hmisc) ``` -It is also straightforward to include figures. For example: +## Build the data frame +From the following link we have downloaded the data we are going to work with in the form of a csv file, and make it into data/ forlder: + + +We assign it to a data frame as follows: +```{r, message=FALSE} +df <- read.csv("data/Wheat.csv",header=T) +df[c(1,2),] +``` -```{r pressure, echo=FALSE} -plot(pressure) +## Clean the data frame +We observe that the first column indicates a sort of an identifier for each data sample. This is not an interesting parameter, so we can simply omit it: +```{r, message=FALSE} +#only keep columns from 2 to 4 (column 1 is omitted) +df <- df[c(2:4)] +df[c(1,2),] ``` -Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible. +## Plotting +```{r, message=FALSE} +# set some parameters +wages_color <- "#ff5733" +wheat_color <- rgb(0.2, 0.6, 0.9, 1) +wheat_color_trans <- rgb(0.2, 0.6, 0.9, 0.5) + +# Start with a usual ggplot2 call: +ggplot(df, aes(x=Year)) + + geom_point( aes(y=Wages), size = 0.7, color = wages_color) + + geom_point( aes(y=Wheat/1.5), size = 0.7, color = wheat_color) + + geom_line( aes(y=Wages), size = 0.3, color = wages_color, linetype="dashed") + + geom_line( aes(y=Wheat/1.5), size = 0.3, color = wheat_color, linetype="dashed") + + stat_smooth(aes(y=Wheat/1.5), level = 0.00, size=0.6, color=wheat_color_trans) + + +# Custom the Y scales: + scale_y_continuous( + # Features of the first axis + name = "Wages", + + # Add a second axis and specify its features + sec.axis = sec_axis( trans=~.*1.5, name="Wheat") + ) + + labs(title = "Title") + + theme(plot.title = element_text(hjust = 0.5), + axis.title.y.left = element_text(colour = wages_color), + axis.title.y.right = element_text(colour = wheat_color)) +``` -Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you. +**Comment:** TBD -Now it's your turn! You can delete all this information and replace it by your computational document.