diff --git a/module3/Exercice_final_M3_TDB.R b/module3/Exercice_final_M3_TDB.R new file mode 100644 index 0000000000000000000000000000000000000000..37f3531fd227642ff3e71dba43343e9f616cc46b --- /dev/null +++ b/module3/Exercice_final_M3_TDB.R @@ -0,0 +1,62 @@ +library(readr) +library(ggplot2) +WheatTDB <- read_csv("module3/WheatTDB.csv") + +#Consigne 1 : + +#Composition des phraphique barplot et puis le tracé bleu puis la courbe rouge +ggplot(WheatTDB, aes(x=factor(Year))) + geom_col(aes(y=Wheat), fill="black") + + geom_ribbon(aes(x=as.numeric(factor(Year)), ymin=0, ymax=Wages), fill="blue", alpha=0.3) + + geom_line(aes(y=Wages, group=1), color="red") + +#Consigne 2 : + +#Supprimer les NA pour éviter l'erreur +wheat <- WheatTDB$Wheat +wages <- WheatTDB$Wages +years <- WheatTDB$Year +good <- !is.na(wheat) & !is.na(wages) + +wheat <- wheat[good] +wages <- wages[good] +years <- years[good] + +#Barres noires = prix du blé +Barplot <- barplot(wheat, names.arg=years, col="black", ylim=c(0, max(wheat, na.rm=TRUE)*1.2), + ylab="Prix du blé (shillings par quart de boisseau)") + +#Ligne rouge = salaire avec axe droit +par(new=TRUE) +plot(Barplot, wages, type="l", col="red", lwd=2, axes=FALSE, xlab="", ylab="", ylim=c(0, max(wages, na.rm=TRUE)*1.2)) +axis(side=4) +mtext("Salaire (shillings par semaine)", side=4, line=3) + +#Consigne 3 : + +#Supprimer les NA +good <- !is.na(WheatTDB$Wheat) & !is.na(WheatTDB$Wages) +years <- WheatTDB$Year[good] +wheat <- WheatTDB$Wheat[good] +wages <- WheatTDB$Wages[good] + +#Pouvoir d'achat = combien de blé un ouvrier peut acheter +PouvoirAchat <- wages / wheat + +#Graphique 1 +plot(years, PouvoirAchat, type="b", pch=16, col="blue", + xlab="Année", ylab="Quantité de blé achetable (quart/semaine)", + main="Pouvoir d'achat des ouvriers") + +#Graphique 2 +Barplot <- barplot(wheat, col="black", ylim=c(0, max(wheat, na.rm=TRUE)*1.2), ylab="Prix du blé (shillings/quarter)", main="Prix du blé et salaire") + +#Superposition la ligne rouge = salaire +par(new=TRUE) +plot(Barplot, wages, type="b", col="red", pch=16, axes=FALSE, xlab="", ylab="", + ylim=c(0, max(wages, na.rm=TRUE)*1.2)) +axis(side=4) +mtext("Salaire (shillings/week)", side=4, line=3) + +#Progression du temps +text(Barplot, wages, labels=1:length(wages), pos=3, cex=0.7) +