forked from ttimbers/equine_numbers_value_canada_rmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhist_horse_pop.Rmd
97 lines (73 loc) · 3.58 KB
/
hist_horse_pop.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: "Historical horse population in Canada"
bibliography: references.bib
params:
province: "Alberta"
output:
github_document:
toc: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
library(knitr)
```
## Aim
This project explores the historical population of horses in Canada between 1906 and 1972 for each Province.
## Data
```{r load data, include = FALSE}
horse_pop <- read_csv("../data/00030067-eng.csv")
horse_pop <- filter(horse_pop,
DATE == "At June 1 (x 1,000)",
GEO != "Canada")
horse_pop$Value <- horse_pop$Value * 1000
```
Horse population data were sourced from the [Government of Canada's Open Data website](http://open.canada.ca/en/open-data). Specifically, these two sources were used:
- [Horses, number on farms at June 1 and at December 1](http://open.canada.ca/data/en/dataset/43b3a9b3-3842-45e7-8bc8-c4c27b9462ab)
- [Horses, number on farms at June 1, farm value per head and total farm value](http://open.canada.ca/data/en/dataset/b374f60b-9580-44dc-83f6-c0a850c15f30)
There was a cool paper about horses once [@milner1969weight].
## Methods
The R programming language [@R] and the following R packages were used to perform the analysis: knitr [@knitr] and tidyverse [@tidyverse]. The code used to perform the analysis and create this report can be found here: https://github.com/ttimbers/equine_numbers_value_canada_rmd.
## Results
```{r plot horses, fig.width=10, fig.height=3, , fig.cap = "Figure 1.Maximum and minimum number of horses for each province between 1940- 1972", out.width="100%" }
horse_plot <- ggplot(horse_pop, aes(x = Ref_Date, y = Value)) +
geom_point() +
geom_line() +
xlab("Year") +
ylab("Number of horses") +
ggtitle("Historical number of horses per province in Canada") +
facet_grid(~GEO) +
scale_y_continuous(labels = scales::comma) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
horse_plot
```
We can see from the visualisation above that Ontario, Saskatchewan and Alberta have had the highest horse populations in Canada. All provinces have had a decline in horse
populations since 1940. This is likely due to the rebound of the Canadian automotive
industry after the Great Depression and the Second World War. An interesting follow-up visualization would be car sales per year for each Province over the time period visualised above to further support this hypothesis.
Next we look at the range of the number horses for each provinces at any time point between 1940 - 1972:
```{r max horse table, message=FALSE, warning=FALSE}
max_horses <- horse_pop %>%
select(GEO, Value) %>%
rename(Province = GEO) %>%
group_by(Province) %>%
summarize(Maximum = max(Value),
Minimum = min(Value))
kable(max_horses,
caption = "Table 1. Maximum and minimum number of horses for each province between 1940- 1972")
```
Below we zoom in and look at the province of `r params$province`:
```{r plot province, fig.width=5, fig.height=4, fig.cap="Figure 2. Maximum and minimum number of horses for each province between 1940- 1972",out.width="50%"}
province_plot <- horse_pop %>%
filter(GEO == params$province) %>%
ggplot(aes(x = Ref_Date, y = Value)) +
geom_point() +
geom_line() +
xlab("Year") +
ylab("Number of horses") +
ggtitle("Historical number of horses per province in Canada") +
facet_grid(~GEO) +
scale_y_continuous(labels = scales::comma) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
province_plot
```
# References