#+TITLE: Le pouvoir d'achat des ouvriers anglais du XVIe au XIXe siècle #+AUTHOR: Thibault #+DATE: <2020-06-11> #+LANGUAGE: fr #+PROPERTY: header-args :session *R* #+OPTIONS: toc:nil #+PROPERTY: results output * COMMENT Consignes #+begin_quote William Playfair était un des pionniers de la présentation graphique des données. Il est notamment considéré comme l'inventeur de l'histogramme. Un de ses graphes célèbres, tiré de son livre "A Letter on Our Agricultural Distresses, Their Causes and Remedies", montre l'évolution du prix du blé et du salaire moyen entre 1565 et 1821. Playfair n'a pas publié les données numériques brutes qu'il a utilisées, car à son époque la réplicabilité n'était pas encore considérée comme essentielle. Des valeurs obtenues par numérisation du graphe sont aujourd'hui téléchargeables, la version en format CSV étant la plus pratique. Quelques remarques pour la compréhension des données : - Jusqu'en 1971, la livre sterling était divisée en 20 shillings, et un shilling en 12 pences. - Le prix du blé est donné en shillings pour un quart de boisseau de blé. Un quart de boisseau équivaut 15 livres britanniques ou 6,8 kg. - Les salaires sont donnés en shillings par semaine. Votre mission si vous l'acceptez : 1. Votre première tâche est de reproduire le graphe de Playfair à partir des données numériques. Représentez, comme Playfair, le prix du blé par des barres et les salaires par une surface bleue délimitée par une courbe rouge. Superposez les deux de la même façon dans un seul graphique. Le style de votre graphique pourra rester différent par rapport à l'original, mais l'impression globale devrait être la même. 2. Par la suite, améliorez la présentation de ces données. Pour commencer, Playfair a combiné les deux quantités dans un même graphique en simplifiant les unités "shillings par quart de boisseau de blé" et "shillings par semaine" à un simple "shillings", ce qui aujourd'hui n'est plus admissible. Utilisez deux ordonnées différentes, une à gauche et une à droite, et indiquez les unités correctes. À cette occasion, n'hésitez pas à proposer d'autres représentations que des barres et des surface/courbes pour les deux jeux de données si ceci vous paraît judicieux. #+end_quote * COMMENT Vincentare analysis :PROPERTIES: :header-args: :eval no :END: #+begin_src R data(Wheat) data(Wheat) # ------------------------------------ # Playfair's graph, largely reproduced # ------------------------------------ # convenience function to fill area under a curve down to a minimum value fillpoly <- function(x,y, low=min(y), ...) { n <- length(x) polygon( c(x, x[n], x[1]), c(y, low, low), ...) } # For best results, this graph should be viewed with width ~ 2 * height # Note use of type='s' to plot a step function for Wheat # and panel.first to provide a background grid() # The curve for Wages is plotted after the polygon below it is filled with(Wheat, { plot(Year, Wheat, type="s", ylim=c(0,105), ylab="Price of the Quarter of Wheat (shillings)", panel.first=grid(col=gray(.9), lty=1)) fillpoly(Year, Wages, low=0, col="lightskyblue", border=NA) lines(Year, Wages, lwd=3, col="red") }) # add some annotations text(1625,10, "Weekly wages of a good mechanic", cex=0.8, srt=3, col="red") # cartouche text(1650, 85, "Chart", cex=2, font=2) text(1650, 70, paste("Shewing at One View", "The Price of the Quarter of Wheat", "& Wages of Labor by the Week", "from the Year 1565 to 1821", "by William Playfair", sep="\n"), font=3) # add the time series bars to show reigning monarchs # distinguish Cromwell visually, as Playfair did with(Wheat.monarchs, { y <- ifelse( !commonwealth & (!seq_along(start) %% 2), 102, 104) segments(start, y, end, y, col="black", lwd=7, lend=1) segments(start, y, end, y, col=ifelse(commonwealth, "white", NA), lwd=4, lend=1) text((start+end)/2, y-2, name, cex=0.5) }) # ----------------------------------------- # plot the labor cost of a quarter of wheat # ----------------------------------------- Wheat1 <- within(na.omit(Wheat), {Labor=Wheat/Wages}) with(Wheat1, { plot(Year, Labor, type='b', pch=16, cex=1.5, lwd=1.5, ylab="Labor cost of a Quarter of Wheat (weeks)", ylim=c(1,12.5)); lines(lowess(Year, Labor), col="red", lwd=2) }) # cartouche text(1740, 10, "Chart", cex=2, font=2) text(1740, 8.5, paste("Shewing at One View", "The Work Required to Purchase", "One Quarter of Wheat", sep="\n"), cex=1.5, font=3) with(Wheat.monarchs, { y <- ifelse( !commonwealth & (!seq_along(start) %% 2), 12.3, 12.5) segments(start, y, end, y, col="black", lwd=7, lend=1) segments(start, y, end, y, col=ifelse(commonwealth, "white", NA), lwd=4, lend=1) text((start+end)/2, y-0.2, name, cex=0.5) }) #+end_src * Reproduction du graphique de Playfair On importe le fichier de données qu'on définit comme fonction pour pouvoir le manipuler: #+begin_src R wheat <- read.csv("Wheat.csv", header = TRUE) #View(wheat) #+end_src #+RESULTS: | 1 | 1565 | 41 | 5 | | 2 | 1570 | 45 | 5.05 | | 3 | 1575 | 42 | 5.08 | | 4 | 1580 | 49 | 5.12 | | 5 | 1585 | 41.5 | 5.15 | | 6 | 1590 | 47 | 5.25 | | 7 | 1595 | 64 | 5.54 | | 8 | 1600 | 27 | 5.61 | | 9 | 1605 | 33 | 5.69 | | 10 | 1610 | 32 | 5.78 | | 11 | 1615 | 33 | 5.94 | | 12 | 1620 | 35 | 6.01 | | 13 | 1625 | 33 | 6.12 | | 14 | 1630 | 45 | 6.22 | | 15 | 1635 | 33 | 6.3 | | 16 | 1640 | 39 | 6.37 | | 17 | 1645 | 53 | 6.45 | | 18 | 1650 | 42 | 6.5 | | 19 | 1655 | 40.5 | 6.6 | | 20 | 1660 | 46.5 | 6.75 | | 21 | 1665 | 32 | 6.8 | | 22 | 1670 | 37 | 6.9 | | 23 | 1675 | 43 | 7 | | 24 | 1680 | 35 | 7.3 | | 25 | 1685 | 27 | 7.6 | | 26 | 1690 | 40 | 8 | | 27 | 1695 | 50 | 8.5 | | 28 | 1700 | 30 | 9 | | 29 | 1705 | 32 | 10 | | 30 | 1710 | 44 | 11 | | 31 | 1715 | 33 | 11.75 | | 32 | 1720 | 29 | 12.5 | | 33 | 1725 | 39 | 13 | | 34 | 1730 | 26 | 13.3 | | 35 | 1735 | 32 | 13.6 | | 36 | 1740 | 27 | 14 | | 37 | 1745 | 27.5 | 14.5 | | 38 | 1750 | 31 | 15 | | 39 | 1755 | 35.5 | 15.7 | | 40 | 1760 | 31 | 16.5 | | 41 | 1765 | 43 | 17.6 | | 42 | 1770 | 47 | 18.5 | | 43 | 1775 | 44 | 19.5 | | 44 | 1780 | 46 | 21 | | 45 | 1785 | 42 | 23 | | 46 | 1790 | 47.5 | 25.5 | | 47 | 1795 | 76 | 27.5 | | 48 | 1800 | 79 | 28.5 | | 49 | 1805 | 81 | 29.5 | | 50 | 1810 | 99 | 30 | | 51 | 1815 | 78 | nil | | 52 | 1820 | 54 | nil | | 53 | 1821 | 54 | nil | On reproduit le graphique de Playfair d'après l'analyse exposée [[https://vincentarelbundock.github.io/Rdatasets/doc/HistData/Wheat.html][ici]]. On définit une fonction qui permet d'établir la moyenne de la pente de la courbe des salaires: #+begin_src R fillpoly <- function(x,y, low=min(y), ...) { n <- length(x) polygon( c(x, x[n], x[1]), c(y, low, low), ...) } #+end_src #+RESULTS: On établit deux représentations graphiques à partir des mêmes axes: l'évolution du prix du quart de boisseau de blé en histogramme, et l'évolution du salaire en courbe. #+begin_src R with(wheat, { plot(Year, Wheat, type="s", ylim=c(0,105), ylab="Price of the Quarter of Wheat (shillings)", panel.first=grid(col=gray(.9), lty=1)) fillpoly(Year, Wages, low=0, col="lightskyblue", border=NA) lines(Year, Wages, lwd=3, col="red") }) #+end_src #+RESULTS: On ajoute les annotations et le cartouche de Playfair: #+begin_src R text(1625,10, "Weekly wages of a good mechanic", cex=0.8, srt=3, col="red") text(1650, 85, "Chart", cex=2, font=2) text(1650, 70, paste("Shewing at One View", "The Price of the Quarter of Wheat", "& Wages of Labor by the Week", "from the Year 1565 to 1821", "by William Playfair", sep="\n"), font=3) #+end_src #+RESULTS: On distingue le prix du travail par quart de boisseau de blé: #+begin_src R Wheat1 <- within(na.omit(Wheat), {Labor=Wheat/Wages}) with(Wheat1, { plot(Year, Labor, type='b', pch=16, cex=1.5, lwd=1.5, ylab="Labor cost of a Quarter of Wheat (weeks)", ylim=c(1,12.5)); lines(lowess(Year, Labor), col="red", lwd=2) }) #+end_src #+RESULTS: \includegraphics{playfair.jpg} \newpage ** COMMENT Ajout d'un cartouche On met un cartouche: #+begin_src R :noeval text(1740, 10, "Chart", cex=2, font=2) text(1740, 8.5, paste("Shewing at One View", "The Work Required to Purchase", "One Quarter of Wheat", sep="\n"), cex=1.5, font=3) #+end_src #+RESULTS: * Nouveau graphe qui distingue les unités #+begin_src R wheat <- read.csv("Wheat.csv", header = TRUE) #View(wheat) #+end_src #+RESULTS: | 1 | 1565 | 41 | 5 | | 2 | 1570 | 45 | 5.05 | | 3 | 1575 | 42 | 5.08 | | 4 | 1580 | 49 | 5.12 | | 5 | 1585 | 41.5 | 5.15 | | 6 | 1590 | 47 | 5.25 | | 7 | 1595 | 64 | 5.54 | | 8 | 1600 | 27 | 5.61 | | 9 | 1605 | 33 | 5.69 | | 10 | 1610 | 32 | 5.78 | | 11 | 1615 | 33 | 5.94 | | 12 | 1620 | 35 | 6.01 | | 13 | 1625 | 33 | 6.12 | | 14 | 1630 | 45 | 6.22 | | 15 | 1635 | 33 | 6.3 | | 16 | 1640 | 39 | 6.37 | | 17 | 1645 | 53 | 6.45 | | 18 | 1650 | 42 | 6.5 | | 19 | 1655 | 40.5 | 6.6 | | 20 | 1660 | 46.5 | 6.75 | | 21 | 1665 | 32 | 6.8 | | 22 | 1670 | 37 | 6.9 | | 23 | 1675 | 43 | 7 | | 24 | 1680 | 35 | 7.3 | | 25 | 1685 | 27 | 7.6 | | 26 | 1690 | 40 | 8 | | 27 | 1695 | 50 | 8.5 | | 28 | 1700 | 30 | 9 | | 29 | 1705 | 32 | 10 | | 30 | 1710 | 44 | 11 | | 31 | 1715 | 33 | 11.75 | | 32 | 1720 | 29 | 12.5 | | 33 | 1725 | 39 | 13 | | 34 | 1730 | 26 | 13.3 | | 35 | 1735 | 32 | 13.6 | | 36 | 1740 | 27 | 14 | | 37 | 1745 | 27.5 | 14.5 | | 38 | 1750 | 31 | 15 | | 39 | 1755 | 35.5 | 15.7 | | 40 | 1760 | 31 | 16.5 | | 41 | 1765 | 43 | 17.6 | | 42 | 1770 | 47 | 18.5 | | 43 | 1775 | 44 | 19.5 | | 44 | 1780 | 46 | 21 | | 45 | 1785 | 42 | 23 | | 46 | 1790 | 47.5 | 25.5 | | 47 | 1795 | 76 | 27.5 | | 48 | 1800 | 79 | 28.5 | | 49 | 1805 | 81 | 29.5 | | 50 | 1810 | 99 | 30 | | 51 | 1815 | 78 | nil | | 52 | 1820 | 54 | nil | | 53 | 1821 | 54 | nil | Les données comportent 3 variables (année, blé, salaire). On améliore le graphique de Playfair en distinguant 2 axes pour avoir l'évolution du prix du blé selon l'année d'une part (unité: quart de boisseau), selon le salair d'un ouvrier d'autre part (unité:) On rajoute de l'espace à droite pour rendre visible le titre de l'axe: #+begin_src R :results silent par(mar=c(5, 4, 4, 5) + 0.1) #+end_src #+RESULTS: | 5.1 | | 4.1 | | 4.1 | | 5.1 | On refait le graphique précédent sans le salaire. On change le type de représentation pour afficher une ligne pleine, on a donc la courbe du prix du blé en fonction du temps: #+begin_src R with(wheat, { plot(Year, Wheat, type="l", ylim=c(0,110), ylab="Price of the Quarter of Wheat (shillings)", col="blue", lty = 1) }) #+end_src #+RESULTS: Pour superposer les 2 courbes, on autoriser la 2^e courbe sur les mêmes axes: #+begin_src R :results silent par(new=TRUE) #+end_src #+RESULTS: : FALSE On trace la courbe du salaire en schillings par semaine. On définit le type de représentation comme ligne pointillée, on créé un nouvel axe à droite et on définit l'échelle de l'axe: #+begin_comment ylim 0,35 pour définir l'échelle de l'axe axes=FALSE pour ne pas utiliser l'axe de gauche légende on définit l'axe de droite dans la dernière ligne #+end_comment #+begin_src R with(wheat, { plot(Year, Wages, type="l", ylim=c(0,35), axes=FALSE,ylab="",col="red", lty = 2) }) mtext("Wages (Schillings/Week)",side=4,col="red",line=4) axis(4, ylim=c(), col="red",col.axis="red",las=1) #+end_src #+RESULTS: | 0 | | 5 | | 10 | | 15 | | 20 | | 25 | | 30 | | 35 | On ajoute une légende en haut à gauche: #+begin_src R :results output graphics :file 2axes.png :exports both legend("topleft", c("Price of Wheat", "Wages"), col = c("blue", "red"), lty = c(1, 2)) #+end_src #+RESULTS: \includegraphics{2axes.jpg}