-
Notifications
You must be signed in to change notification settings - Fork 2
/
RMarkdownExercises.Rmd
49 lines (36 loc) · 1.33 KB
/
RMarkdownExercises.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
---
title: "R Markdown training exercises"
author: "Ministry of Justice"
date: "14/03/2019"
output:
word_document:
reference_docx: mystyles.docx
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
crimedata <- read.csv("crimedata.csv")
```
## Exercises
Recreate the following plot and text using what you have learnt in this training. You may find the cheatsheet and help window useful. Check your code works by swapping between the two data sets as before.
```{r echo=FALSE}
library(ggplot2)
ggplot(crimedata, aes(year, crimes)) + geom_line(colour="blue") + expand_limits(y=c(0,200)) + ggtitle("Total number of crimes per year")
```
```{r echo = FALSE, include=FALSE}
library(dplyr)
crimedata <- arrange(crimedata,year)
firstyear <- first(crimedata$year)
latestyear <- last(crimedata$year)
```
*Crime data is available from `r firstyear` to `r latestyear`.*
```{r echo=FALSE, include=FALSE}
meancrimes <- round(mean(crimedata$crimes), digits = 1)
mediancrimes <- median(crimedata$crimes)
mincrimes <- min(crimedata$crimes)
maxcrimes <- max(crimedata$crimes)
```
## Crime summary statistics
* **Across this period;**
+ *The mean number of crimes was `r meancrimes`.*
+ *The median number of crimes was `r mediancrimes`.*
+ *The number of crimes per year varied from `r mincrimes` to `r maxcrimes`.*