-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aflevering_uge_12.Rmd
117 lines (82 loc) · 6.35 KB
/
Aflevering_uge_12.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: "Are we more civilized today?"
author: "Magnus Vrang Thomsen & Laurits Corydon Dybdahl"
date: " created 4 October 2021, updated ..."
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
message=FALSE)
```
This exercise is based on the dataset provided by [OurWorldInData project](https://ourworldindata.org/homicides) based at the Oxford University.
## The long-term trend in Homicides in Western Europe
Understanding how homicide rates have changed prior to the modern era requires the help of historians and archivists. Manuel Eisner, a criminology professor at the University of Cambridge, and his colleagues published the Historical Violence Database \href{https://cjrc.osu.edu/research/interdisciplinary/hvd}: a compilation of data on long-term trends in homicide rates, in addition to qualitative information such as the cause of death, perpetrator and victim. This database is limited to countries with relatively complete historical records on violence and crime – mainly Western Europe and the US.
Starting in the second half of the nineteenth century, these European regions have consistent police records of those accused of murder or manslaughter and annual counts of homicide victims. To go back further in time, reaching as far back as the thirteenth century, Eisner collected estimates (from historical records of coroner reports, court trials, and the police) of homicide rates made in over ninety publications by scholars.
Homicide rates – measured as the number of homicides per 100,000 individuals – up to 1990 are sourced from Eisner’s (2003) publication and the Historical Violence Database.
Are homicide rates in Europe today lower or higher than in the past? Using the provided dataset, display and describe the long-run homicide rates for the five European regions: Italy, England, Germany, Netherlands and Scandinavia.
```{r library}
library(tidyverse)
```
## Load the available data from ourworldindata.org
You should always interrogate the source of your data. Who compiled it, from where, what is missing, how representative the data are? Check the data/Metadata.txt to learn about the data provenance.
```{r load-data}
Western_Europe <- read_csv("data/homicide-rates-across-western-europe.csv")
```
## Inspect the data
How clean and analysis-ready is the dataset? Do you understand what the column names represent? What is the difference between rate and homicide number?
```{r inspect}
head(Western_Europe)
```
Ok, the data look good except for the column `Homicide rate in Europe over long-term (per 100,000)` which is not very easy to work with.
- Use the `names()` function and assignment key to relabel this column to `homicides_per_100k`
```{r relabel column}
# YOUR Code
names(Western_Europe)
homicides_per_100k <- Western_Europe[4]
```
Now, that you have looked at what the data looks like and what it represents, and streamlined it, let's see what big picture it contains.
## Let's see what the long-term trend is in homicides
- use `ggplot()` function and remember the`+` at the end of the line
- chose a meaningful `geom_......()` for geometry (hint: points are not great)
- load `Year` on the `x` axis and `homicides_per_100k` column in y axis
- to color individual country entries consistently, assign the country column to the argument `color`.
- provide meaningful title and axis labels
- remember to change the `eval` flag so that the code chunk renders when knitted
```{r plot-homicides, eval = TRUE}
Year_vector <- Western_Europe[[3]]
homicides_per_100k_vector <- Western_Europe[[4]]
ggplot(data=Western_Europe)+
aes(x=Year_vector,y=homicides_per_100k_vector)+
geom_jitter(color="green")
```
Alright, the homicide rates should all be descending over time. What a comfort. But the viz is not super clear. Let's check the rates for individual countries.
## Uncouple the homicides of individual countries for easier view
You can visualize each country's trend separately by adding an extra argument to the ggplot, the `facet_wrap()` and feeding it the country column. If in doubt, check your ggplot tutorial and your country column name for exact usage.
- reuse the ggplot from the chunk above
- insert `facet_wrap()` after the specification of geometry to split countries in separate charts
- change the facet "layout" to two columns and three rows so that the trends are easier to see in horizontal layout.
```{r eval = FALSE}
#... YOUR CODE
Year_vector <- Western_Europe[[3]]
homicides_per_100k_vector <- Western_Europe[[4]]
country <- Western_Europe[[1]]
```
## Compare the trends in homicide with the pattern of reign duration among Danish rulers through time.
- Load your Danish king dataset. Hopefully it is tidy and your years and duration of reign are all numeric.
- You need to have a consistent way of plotting the rulers' reign on the x axis, so I recommend you create a midyear column by calculating the middle of each monarch's rule (Hint: `midyear` = `endyear` - (`endyear`-`startyear`)/2)
- Start a ggplot plotting midyear on x axis and duration on y axis
- Try `geom_smooth()` for geometry
- Provide meaningful labels and a title
- How would you characterize the trend compared to the homicides above?
```{r eval = FALSE}
# YOUR CODE HERE:
```
**Final tasks:**
1) Plot: In the facetted plot above, move the legend from the current position on the side to below the facets, and label it "Country" instead of "Entity".
2) Rmarkdown:
- edit the author of the document, and convert 'Final Tasks' into heading #2 (like the other headings)
- add a `floating table of contents` to your Rmarkdown document,
- provide informative `chunk-names` and edit flags in your R chunks, and
- automatically generate a `timestamp` to show when the document was last updated. (Hint: check the Rmarkdown episode in our Data Carpentry tutorial)
3) Question: In <250 words articulate your answer on the basis of the data visualisations to the following question: are we more civilized today?
The visualisation shows a clear decline in homocides in England, Italy along with the other countries from the dataset. So it shows that these countries are more civilized, however it does not say anything about all the other countries that are not included in the dataset, and therefore it is impossible to give a conclusive answer to the question in general, only that the countries in the dataset have grown more civilized over time.