ggplot(jeuB) + geom_bar(aes(x=Year, y=Wheat), stat = "identity", colour="black") + geom_area(aes(x=Year, y=Wages), fill="lightblue", alpha=0.7) + geom_line(aes(x=Year, y=Wages), color="red") + ggtitle("Playfair plot") + labs(x="Year", y= "Weekly wage in shillings") + scale_y_continuous(sec.axis = sec_axis(~.+0, name = "Price of the quarter of wheats in shillings"), position = "left") + theme_bw()
```
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 <http://rmarkdown.rstudio.com>.
## Question two
Improved presentation of data. The unit "shillings per quarter of bushel of wheat" is replaced by "shillings per kg of wheat" and "shillings per week" by "shillings per year" (leap years will not be taken into account here).
```{r}
ggplot(jeuB) + geom_bar(aes(x=Year, y=Wheat/6.8), stat = "identity", colour="black") + labs(x="Year", y= "Yearly wage in shillings") + geom_area(aes(x=Year, y=Wages*52), fill="lightblue", alpha=0.7) + geom_line(aes(x=Year, y=Wages*52), color="red") + ggtitle("Playfair plot") + scale_y_continuous(sec.axis = sec_axis(~.+0, name = "Wheat price per kg in shillings"), position = "left") + theme_bw()
```
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:
In this form, the graph is not very relevant: we do not observe the relationship between the 2 units used and the evolution of the price of wheat is invisible.
```{r cars}
summary(cars)
Consequently, we modify the graph in order to obtain a more relevant scale for the price of wheat.
```{r}
ggplot(jeuB) + geom_bar(aes(x=Year, y=(Wheat/6.8)*200), stat = "identity", colour="black") + labs(x="Year", y= "Yearly wage in shillings") + geom_area(aes(x=Year, y=Wages*52), fill="lightblue", alpha=0.7) + geom_line(aes(x=Year, y=Wages*52), color="red") + ggtitle("Playfair plot") + scale_y_continuous(sec.axis = sec_axis(~./200, name = "Wheat price per kg in shillings"), position = "left") + theme_bw()
```
It is also straightforward to include figures. For example:
## Question three
Here we will make a graphical representation of the purchasing power of workers over time.
First, we define purchasing power as the quantity of wheat that a worker can buy with his weekly salary.
```{r}
ggplot(data = jeuB, aes(x=Year, y=Wages/(Wheat/6.8))) + geom_line(color="red") + labs (x="Year", y="Quantity of wheat (in kg) that a worker can weekly buy") + ggtitle("Evolution of the spending power during time") + theme_bw()
```
On this graph, we observe that the purchasing power of the workers increases gradually over time, until about the 1730s when it begins to stagnate, then to decrease around the 1780s. However, even with this decrease, purchasing power remains significantly higher than in the years before 1700.
```{r pressure, echo=FALSE}
plot(pressure)
We then observe the evolution of the price of wheat as a function of (annual) wages.
```{r}
ggplot(data = jeuB, aes(x=Wages*52, y=Wheat/6.8)) + geom_point(aes(color = cut(Year, c(-Inf, 1700, 1730, 1780, Inf)))) + scale_color_manual(name = "Year", values=wes_palette(n=4, name="FantasticFox1"), labels = c("before 1700", "between 1700 and 1730", "between 1730 and 1780", "after 1780")) + geom_smooth(fill="lightgrey") + labs (x="Yearly wage in shillings", y="Wheat price per kg in shillings") + ggtitle("Evolution of the price of the wheat depending on the wages") + theme_bw()
```
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.
On the graph above, it seems that the higher the price of wheat (per kilo), the more the wages are too. According to the Playfair graph, this is explained by the fact that wages increase over time. The same goes for the price of wheat but unevenly for it.
According to the data, workers' wages increase over time without an exceptional moment.
In the graph below, we have therefore replaced the time axis with that of the annual salary.
```{r}
ggplot(data = jeuB, aes(x=Wages*52, y=Wages/(Wheat/6.8))) + geom_line(color="blue") + labs (x="Yearly wage in shillings", y="Quantity of wheat (in kg) that a worker can weekly buy") + ggtitle("Evolution of the spending power depending on the wages") + theme_bw()
```
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.
Here we find a curve showing an evolution in the purchasing power of workers in the same idea as the first graph. However, the significant increase in purchasing power is less evident here.
Now it's your turn! You can delete all this information and replace it by your computational document.
If we want to show that the purchasing power of workers increases over time, we therefore find that the first curve is the most relevant among these graphs.