From 288b61642419bac29cb58308869a23b8e36d6b06 Mon Sep 17 00:00:00 2001 From: Del Ben Tom Date: Mon, 8 Sep 2025 13:54:31 +0200 Subject: [PATCH] =?UTF-8?q?Tous=20les=20graphiques=20bons=20et=20corrig?= =?UTF-8?q?=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Exercice final M3 TDB.R | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Exercice final M3 TDB.R diff --git a/Exercice final M3 TDB.R b/Exercice final M3 TDB.R new file mode 100644 index 0000000..04a77d5 --- /dev/null +++ b/Exercice final M3 TDB.R @@ -0,0 +1,61 @@ +library(readr) +library(ggplot2) +WheatTDB <- read_csv("module3/WheatTDB.csv") + +#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 n2 + +# 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") + +# Superposer 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) + +# Numéros pour indiquer la progression du temps +text(Barplot, wages, labels=1:length(wages), pos=3, cex=0.7) + -- 2.18.1