---
title: "Family Incidents in Victoria"
author: "Tim Zhihang Jian"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(plotly)
library(maps)
library(flexdashboard)
library(ggplot2)
library(dplyr)
library(tidyr)
library(rgeos)
library(maptools)
library(ggmap)
library(broom)
library(maps)
library(mapproj)
library(scales)
library(readxl)
knitr::opts_chunk$set(message = FALSE)
```
Visualisations
==============================================================================
Row {data-height=550}
------------------------------------------------------------------------------
### Family Incidents in each Victoria Local Government Area
```{r}
# plot1
#load the data
#load the shape file
sfile1 <- readShapeSpatial("/Users/noalgreen/Desktop/DVA3/vmlite_lga_cm//vmlite_lga_cm.shp")
# load the excel file
total <- read_excel("/Users/noalgreen/Desktop/DVA3/total.xlsx")
# convert the shp file to a data.frame.
sfile2 <- tidy(sfile1, region = "lga_name")
# Get the lga_name for merging purposes
sfile2$lga_name <-sfile2$id
# Merge the two data sources
choro <- total %>% left_join(sfile2, by = "lga_name", all.x=TRUE)
chorodf<-choro[order(choro$order), ]
# Create the Choropleth map
p1.1 <- ggplot(data = chorodf,
aes(x = long,
y = lat,
group = group,
text = paste(lga),
fill = mean))
p1.2 <- p1.1 + geom_polygon(color = "black", size = 0.25) +
coord_map() +
scale_fill_distiller(name = "Average Cases \n during 2017 to 2021",
guide = "colorbar",
palette = "YlOrRd", direction = 1,
na.value = "#dddddd", labels = comma,
limits = c(0,5000), oob = squish) +
theme_minimal() + theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
panel.grid = element_blank()) +
labs(title="Average Family Incidents Cases Happened \n in Each Local Government Area Victoria (2017-2021)")
ggplotly(p1.2, tooltip = c( "text", "fill"))
```
### Group by Police Regions
```{r}
total3 <- read_excel("/Users/noalgreen/Desktop/DVA3/total3.xlsx")
total3 <- total3 %>% pivot_longer(names_to = "year", values_to = "cases", cols = 2:6)
p3 <- ggplot(data = total3, aes(x = year, y = cases, fill = cases, text = paste(lga), color = region)) +
geom_point() +
scale_fill_distiller(name = " Cases",
guide = "colorbar",
palette = "YlGN", direction = 1,
na.value = "#dddddd", labels = comma,
limits = c(0,5000), oob = squish) +
labs(title="Family Incidents Recorded in Victoria Police Region(2017-2021)",
)
p3 <- ggplotly(p3, tooltip = c("fill", "text"))
p3
```
Row {data-height=450}
------------------------------------------------------------------------------
### How old are the victims
```{r}
age <- read_excel("/Users/noalgreen/Desktop/DVA3/age.xlsx")
age1 <- age %>% pivot_longer(names_to = "gender", values_to = "cases", cols = 2:3)
p2 <- plot_ly(data = age1, x = ~cases, y = ~Age, tpye = "bar", color = ~gender, colors = c("#67a9cf","#ef8a62")) %>%
layout(title = "Victim Numbers in Each Age Group",
yaxis = list(zeroline = FALSE, title = "Age Group"),
xaxis = list(zeroline = FALSE, title = "Cases"))
p2
```
### Which types are the incidents
```{r}
type <- read_excel("/Users/noalgreen/Desktop/DVA3/type.xlsx")
type <- type %>% select(type, proportion)
text <- c("30 cases","24185 cases","5442 cases","423 cases","64 cases","48 cases","8151 cases","1494 cases","57234 cases","12017 cases","4665 cases")
p4 <- plot_ly(data = type, x = ~type, y = ~proportion, color = ~type, text = text, tpye = "bar") %>%
layout(title = "Common Famlily Incident Types",
yaxis = list(zeroline = FALSE, title = "Percentage of Family Incidents"),
xaxis = list(zeroline = FALSE, title = "Criminal Types"),
showlegend = FALSE)
p4
```
### Who are the offenders
```{r, error=TRUE}
relationship <- read_excel("/Users/noalgreen/Desktop/DVA3/relationship.xlsx")
relationship <- relationship %>%
pivot_longer(names_to = "year", values_to = "count", cols = 2:6)
p5 <- plot_ly(data = relationship, x = ~Relationship, y = ~count, color = ~Relationship, tpye = "bar") %>%
layout(title = "Relationship Between Victims and Offenders ",
yaxis = list(zeroline = FALSE, title = ""),
xaxis = list(zeroline = FALSE, title = "Relationship"))
p5
```
References
================================================================================
* Crime Statistic Agency Victoria State Government, Victoria Police Data Table : Family incidents recorded by police region and local government area, July 2016 to June 2021, viewed 29 May 2022, https://www.crimestatistics.vic.gov.au/family-violence-data-portal/download-data-tables
* Crime Statistic Agency Victoria State Government, Victoria Police Data Table : Affected family members by sex and age, July 2016 to June 2021, viewed 29 May 2022, https://www.crimestatistics.vic.gov.au/family-violence-data-portal/download-data-tables
* Crime Statistic Agency Victoria State Government, Victoria Police Data Table : AOffences recorded by offence categories and family incident flag, July 2016 to June 2021, July 2016 to June 2021, viewed 29 May 2022, https://www.crimestatistics.vic.gov.au/family-violence-data-portal/download-data-tables
* Crime Statistic Agency Victoria State Government, Victoria Police Data Table : Relationship of affected family member and other party by sex of the affected family member, July 2016 to June 2021, viewed 29 May 2022, https://www.crimestatistics.vic.gov.au/family-violence-data-portal/download-data-tables