-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtutorial8.qmd
More file actions
59 lines (45 loc) · 1.56 KB
/
tutorial8.qmd
File metadata and controls
59 lines (45 loc) · 1.56 KB
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
---
title: "Tutorial8"
format: html
editor: visual
---
```{r}
library(readr)
library(ggplot2)
library(tidyverse)
```
```{r}
Data_Tutorial <- read_csv("Data_Tables_Criminal_Incidents_Visualisation_Year_Ending_December_2019.csv")
```
```{r}
# Group by 'Year' and 'Offence Division', and summarize the total Incidents Recorded
data_summary <- Data_Tutorial %>%
group_by(Year, `Offence Division`) %>%
summarise(Total_Incidents = sum(`Incidents Recorded`))
# Create ggplot
ggplot(data_summary, aes(x = Year, y = Total_Incidents, color = `Offence Division`)) +
geom_line() +
geom_point() +
labs(title = "Total Incidents Recorded by Year and Offence Division",
x = "Year",
y = "Total Incidents Recorded",
color = "Offence Division") +
theme_minimal()
```
```{r}
ggplot(data = Data_Tutorial, aes(x = `Incidents Recorded`, y = `Rate per 100,000 population`, color = `Offence Division`)) +
geom_point() + # Use points for a scatter plot
labs(title = "Relationship between Incidents and Rate per 100,000 Population",
x = "Incidents Recorded",
y = "Rate per 100,000 Population") +
theme_minimal() # Use a minimal theme for simplicity
```
```{r}
# Create a boxplot with ggplot
ggplot(data = Data_Tutorial, aes(x = `Offence Division`, y = `Incidents Recorded`, fill = `Offence Division`)) +
geom_boxplot() + # Use boxplots to visualize the distribution
labs(title = "Distribution of Incidents Recorded by Offence Division",
x = "Offence Division",
y = "Incidents Recorded") +
theme_minimal() # Use a minimal theme
```