---
title: "Victims in Australia Records (2010-2019)"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: [ "twitter", "facebook", "menu" ]
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(tidyr)
library(knitr)
library(DT)
library(ggplot2)
library(plotly)
library(readr)
library(readxl)
library(extrafont)
library(ggthemes)
library(ozmaps)
library(sf)
```
```{r}
Book3 <- read_excel("Book3.xlsx")
victim <- Book3
#----------------------------------------------------------------------
#Data Wrangling.
#Deleting unwanted rows from header.
victim <- victim[-c(1,2,3,4), ]
#Deleting unwanted columns.
victim <- victim[-c(12:21)]
#----------------------------------------------------------------------
#Slicing data to create new nsw data frame for New South Wales.
nsw <- slice(victim, c(1:26))
nsw$location <- "NSW"
#Renaming column names.
nsw <- nsw %>% rename( 'Offence' = 'Australian Bureau of Statistics',
'2010' = '...2', '2011' = '...3', '2012' = '...4',
'2013' = '...5', '2014' = '...6', '2015' = '...7',
'2016' = '...8', '2017' = '...9', '2018' = '...10',
'2019' = '...11', 'Location' = 'location')
#Removing unwanted rows.
nsw <- nsw[-c(1,2,7,9,11,13,17,19,23,25),]
#Changing the nsw data frame to long format.
nsw <- gather(nsw, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#-----------------------------------------------------------------------
#Slicing data to create new data frame for Victoria.
vic <- slice(victim, c(28:51))
vic$Location <- "VIC"
#Renaming columns.
vic <- vic %>% rename( 'Offence' = 'Australian Bureau of Statistics',
'2010' = '...2', '2011' = '...3', '2012' = '...4',
'2013' = '...5', '2014' = '...6', '2015' = '...7',
'2016' = '...8', '2017' = '...9', '2018' = '...10',
'2019' = '...11')
#Removing unwanted rows.
vic <- vic[-c(5,7,9,11,15,17,21,23),]
#Changing the data to long format.
vic <- gather(vic, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#----------------------------------------------------------------------
#Slicing data to create new data frame for Queensland.
qld <- slice(victim, c(53:76))
qld$Location <- "QLD"
#Renaming columns.
qld <- qld %>% rename( 'Offence' = 'Australian Bureau of Statistics',
'2010' = '...2', '2011' = '...3', '2012' = '...4',
'2013' = '...5', '2014' = '...6', '2015' = '...7',
'2016' = '...8', '2017' = '...9', '2018' = '...10',
'2019' = '...11')
#Removing unwanted rows.
qld <- qld[-c(5,7,9,11,15,17,21,23),]
#Changing the data to long format.
qld <- gather(qld, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#------------------------------------------------------------------------
##Slicing data to create new data frame for South Australia.
sa <- slice(victim, c(78:101))
sa$Location <- "SA"
#Renaming columns.
sa <- sa %>% rename( 'Offence' = 'Australian Bureau of Statistics',
'2010' = '...2', '2011' = '...3', '2012' = '...4',
'2013' = '...5', '2014' = '...6', '2015' = '...7',
'2016' = '...8', '2017' = '...9', '2018' = '...10',
'2019' = '...11')
#Removing unwanted rows.
sa <- sa[-c(5,7,9,11,15,17,21,23),]
#Changing the data to long format.
sa <- gather(sa, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#-----------------------------------------------------------------------
#Slicing data to create new data frame for Western Australia.
wa <- slice(victim, c(103:126))
wa$Location <- "WA"
#Renaming columns.
wa <- wa %>% rename( 'Offence' = 'Australian Bureau of Statistics',
'2010' = '...2', '2011' = '...3', '2012' = '...4',
'2013' = '...5', '2014' = '...6', '2015' = '...7',
'2016' = '...8', '2017' = '...9', '2018' = '...10',
'2019' = '...11')
#Removing unwanted rows.
wa <- wa[-c(5,7,9,11,15,17,21,23),]
#Changing the data to long format.
wa <- gather(wa, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#--------------------------------------------------------------------------
#Slicing data to create new data frame for Tasmania.
tas <- slice(victim, c(128:151))
tas$Location <- "TAS"
#Renaming columns.
tas <- tas %>% rename( 'Offence' = 'Australian Bureau of Statistics',
'2010' = '...2', '2011' = '...3', '2012' = '...4',
'2013' = '...5', '2014' = '...6', '2015' = '...7',
'2016' = '...8', '2017' = '...9', '2018' = '...10',
'2019' = '...11')
#Removing unwanted rows.
tas <- tas[-c(5,7,9,11,15,17,21,23),]
#Changing the data to long format.
tas <- gather(tas, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#----------------------------------------------------------------------------
#Slicing data to create new data frame for Northern Territory.
nt <- slice(victim, c(153:176))
nt$Location <- "NT"
#Renaming columns.
nt <- nt %>% rename( 'Offence' = 'Australian Bureau of Statistics',
'2010' = '...2', '2011' = '...3', '2012' = '...4',
'2013' = '...5', '2014' = '...6', '2015' = '...7',
'2016' = '...8', '2017' = '...9', '2018' = '...10',
'2019' = '...11')
#Removing unwanted rows.
nt <- nt[-c(5,7,9,11,15,17,21,23),]
#Changing the data to long format.
nt <- gather(nt, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#-----------------------------------------------------------------------------
#Slicing data to create new data frame for Australian Capital Territory.
act <- slice(victim, c(178:201))
act$Location <- "ACT"
#Renaming columns.
act <- act %>% rename( 'Offence' = 'Australian Bureau of Statistics',
'2010' = '...2', '2011' = '...3', '2012' = '...4',
'2013' = '...5', '2014' = '...6', '2015' = '...7',
'2016' = '...8', '2017' = '...9', '2018' = '...10',
'2019' = '...11')
#Removing unwanted rows.
act <- act[-c(5,7,9,11,15,17,21,23),]
#Changing the data to long format.
act <- gather(act, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#-----------------------------------------------------------------------------
#Joining the data frames to a new dataset.
final <- full_join(nsw, vic)
final <- full_join(final, qld)
final <- full_join(final, sa)
final <- full_join(final, wa)
final <- full_join(final, tas)
final <- full_join(final, nt)
final <- full_join(final, act)
#Changing the data types.
final$Year <- as.integer(final$Year)
final$Count <- as.numeric(final$Count)
#Excluding the rows with NA values and taking complete cases.
final <- final[complete.cases(final),]
#Spreading values for Time Series Chart.
stateSum <- final %>% group_by(Location, Year) %>% summarise(totalCount = sum(Count), na.rm = TRUE)
stateSpread <- spread(stateSum, key = Location, value = totalCount)
#Creating data frames for victim count for each year.
abc <- stateSum
abc$Location[abc$Location == 'VIC'] <- "Victoria"
abc$Location[abc$Location == 'NSW'] <- "New South Wales"
abc$Location[abc$Location == 'QLD'] <- "Queensland"
abc$Location[abc$Location == 'SA'] <- "South Australia"
abc$Location[abc$Location == 'WA'] <- "Western Australia"
abc$Location[abc$Location == 'TAS'] <- "Tasmania"
abc$Location[abc$Location == 'NT'] <- "Northern Territory"
abc$Location[abc$Location == 'ACT'] <- "Australian Capital Territory"
#Changing Location column name to Name to join it with the state coordinates from Aus_States.
abc <- abc %>% rename( 'NAME' = 'Location')
#Getting Australian state and their coordinates.
Aus_States <- ozmap_data("states")
Aus_States <- Aus_States[-c(9),]
#Joining data frame with the Aus_State data frame.
abc <- left_join(Aus_States, abc, by = "NAME")
sf_oz <- Aus_States
#Filtering victim records for each year.
y2010 <- filter(abc, Year == "2010")
y2011 <- filter(abc, Year == "2011")
y2012 <- filter(abc, Year == "2012")
y2013 <- filter(abc, Year == "2013")
y2014 <- filter(abc, Year == "2014")
y2015 <- filter(abc, Year == "2015")
y2016 <- filter(abc, Year == "2016")
y2017 <- filter(abc, Year == "2017")
y2018 <- filter(abc, Year == "2018")
y2019 <- filter(abc, Year == "2019")
#Sumarising data for map.
totalCount <- abc %>% group_by(NAME) %>% summarise(total = sum(totalCount))
totalCount$total <- round(totalCount$total/1000000, digits = 2)
totalCount$Hover <- paste(totalCount$NAME,"\n", totalCount$total)
##############################################################################
##############################################################################
Age_Sex_Data <- read_excel("Age_Sex_Data.xlsx", skip = 5)
data2 <- Age_Sex_Data
#---------------------------------------------------
#Slicing data for Homicides.(MALE)
hom_male <- slice(data2, c(7))
hom_male <- hom_male %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
hom_male <- hom_male[-c(1, 12:21)]
#Changing the data frame to long format.
hom_male <- gather(hom_male, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
hom_male$Gender <- "Male"
hom_male$Offence <- "Homicide and related offences"
#---------------------------------------------------
#Slicing data for Homicides.(FEMALE)
hom_female <- slice(data2, c(13))
hom_female <- hom_female %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
hom_female <- hom_female[-c(1, 12:21)]
#Changing the data frame to long format.
hom_female <- gather(hom_female, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
hom_female$Gender <- "Female"
hom_female$Offence <- "Homicide and related offences"
#---------------------------------------------------
#Slicing data for Murder.(MALE)
mur_male <- slice(data2, c(26))
mur_male <- mur_male %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
mur_male <- mur_male[-c(1, 12:21)]
#Changing the data frame to long format.
mur_male <- gather(mur_male, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
mur_male$Gender <- "Male"
mur_male$Offence <- "Murder"
#---------------------------------------------------
#Slicing data for Murder.(FEMALE)
mur_female <- slice(data2, c(32))
mur_female <- mur_female %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
mur_female <- mur_female[-c(1, 12:21)]
#Changing the data frame to long format.
mur_female <- gather(mur_female, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
mur_female$Gender <- "Female"
mur_female$Offence <- "Murder"
#---------------------------------------------------
#Slicing data for Attempted Murder.(MALE)
attmur_male <- slice(data2, c(45))
attmur_male <- attmur_male %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
attmur_male <- attmur_male[-c(1, 12:21)]
#Changing the data frame to long format.
attmur_male <- gather(attmur_male, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
attmur_male$Gender <- "Male"
attmur_male$Offence <- "Attempted Murder"
#---------------------------------------------------
#Slicing data for Attempted Murder.(FEMALE)
attmur_female <- slice(data2, c(51))
attmur_female <- attmur_female %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
attmur_female <- attmur_female[-c(1, 12:21)]
#Changing the data frame to long format.
attmur_female <- gather(attmur_female, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
attmur_female$Gender <- "Female"
attmur_female$Offence <- "Attempted Murder"
#---------------------------------------------------
#Slicing data for Manslaughter.(MALE)
man_male <- slice(data2, c(64))
man_male <- man_male %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
man_male <- man_male[-c(1, 12:21)]
#Changing the data frame to long format.
man_male <- gather(man_male, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
man_male$Gender <- "Male"
man_male$Offence <- "Manslaughter"
#---------------------------------------------------
#Slicing data for Manslaughter.(FEMALE)
man_female <- slice(data2, c(70))
man_female <- man_female %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
man_female <- man_female[-c(1, 12:21)]
#Changing the data frame to long format.
man_female <- gather(man_female, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
man_female$Gender <- "Female"
man_female$Offence <- "Manslaughter"
#---------------------------------------------------
#Slicing data for Sexual assault.(MALE)
sa_male <- slice(data2, c(88))
sa_male <- sa_male %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
sa_male <- sa_male[-c(1, 12:21)]
#Changing the data frame to long format.
sa_male <- gather(sa_male, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
sa_male$Gender <- "Male"
sa_male$Offence <- "Sexual Assault"
#---------------------------------------------------
#Slicing data for Sexual assault.(FEMALE)
sa_female <- slice(data2, c(99))
sa_female <- sa_female %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
sa_female <- sa_female[-c(1, 12:21)]
#Changing the data frame to long format.
sa_female <- gather(sa_female, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
sa_female$Gender <- "Female"
sa_female$Offence <- "Sexual Assault"
#---------------------------------------------------
#Slicing data for Kidnapping/abduction.(MALE)
kd_male <- slice(data2, c(121))
kd_male <- kd_male %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
kd_male <- kd_male[-c(1, 12:21)]
#Changing the data frame to long format.
kd_male <- gather(kd_male, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
kd_male$Gender <- "Male"
kd_male$Offence <- "Kidnapping/Abduction"
#---------------------------------------------------
#Slicing data for Sexual assault.(FEMALE)
kd_female <- slice(data2, c(131))
kd_female <- kd_female %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
kd_female <- kd_female[-c(1, 12:21)]
#Changing the data frame to long format.
kd_female <- gather(kd_female, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
kd_female$Gender <- "Female"
kd_female$Offence <- "Kidnapping/Abduction"
#---------------------------------------------------
#Slicing data for Robbery.(MALE)
rob_male <- slice(data2, c(153))
rob_male <- rob_male %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
rob_male <- rob_male[-c(1, 12:21)]
#Changing the data frame to long format.
rob_male <- gather(rob_male, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
rob_male$Gender <- "Male"
rob_male$Offence <- "Robbery"
#---------------------------------------------------
#Slicing data for Robbery.(FEMALE)
rob_female <- slice(data2, c(164))
rob_female <- rob_female %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
rob_female <- rob_female[-c(1, 12:21)]
#Changing the data frame to long format.
rob_female <- gather(rob_female, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
rob_female$Gender <- "Female"
rob_female$Offence <- "Robbery"
#---------------------------------------------------
#Slicing data for Blackmail/extortion.(MALE)
bck_male <- slice(data2, c(254))
bck_male <- bck_male %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
bck_male <- bck_male[-c(1, 12:21)]
#Changing the data frame to long format.
bck_male <- gather(bck_male, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
bck_male$Gender <- "Male"
bck_male$Offence <- "BlackMail/Extortion"
#---------------------------------------------------
#Slicing data for Armed Robbery.(FEMALE)
bck_female <- slice(data2, c(264))
bck_female <- bck_female %>% rename( '2010' = '2010...2', '2011' = '2011...3', '2012' = '2012...4',
'2013' = '2013...5', '2014' = '2014...6', '2015' = '2015...7',
'2016' = '2016...8', '2017' = '2017...9', '2018' = '2018...10',
'2019' = '2019...11')
#Deleting unwanted cols.
bck_female <- bck_female[-c(1, 12:21)]
#Changing the data frame to long format.
bck_female <- gather(bck_female, '2010','2011','2012','2013','2014','2015','2016',
'2017','2018','2019', key = "Year", value = "Count")
#Adding Cols.
bck_female$Gender <- "Female"
bck_female$Offence <- "BlackMail/Extortion"
#---------------------------------------------------
#Merging dataframes.
final2 <- full_join(hom_male, hom_female)
final2 <- full_join(final2, mur_male)
final2 <- full_join(final2, mur_female)
final2 <- full_join(final2, attmur_male)
final2 <- full_join(final2, attmur_female)
final2 <- full_join(final2, man_male)
final2 <- full_join(final2, man_female)
final2 <- full_join(final2, mur_male)
final2 <- full_join(final2, sa_male)
final2 <- full_join(final2, sa_female)
final2 <- full_join(final2, kd_male)
final2 <- full_join(final2, kd_female)
final2 <- full_join(final2, rob_male)
final2 <- full_join(final2, rob_female)
final2 <- full_join(final2, bck_male)
final2 <- full_join(final2, bck_female)
#----------------------------------------------------
#Changing the data types.
final2$Year <- as.integer(final2$Year)
final2$Count <- as.numeric(final2$Count)
data2Sum <- final2 %>% group_by(Offence, Gender) %>% summarise(totalCount = sum(Count), na.rm = TRUE)
#----------------------------------------------------
#Joining Final and Final2.
dataTable <- left_join(final, final2)
#Offence Types and Count.
offence_types <- final2 %>% group_by(Offence) %>% summarise(Total = sum(Count))
offence_types<- arrange(offence_types, desc(Total))
#Data frame to create Offences vs Gender bar plot.
test <- final2 %>% group_by(Offence, Gender) %>% summarise(Total = sum(Count))
#Data frame to show the number of incidents every year.
tc <- final %>% group_by(Year) %>% summarise(total = sum(Count))
```
Home
=============================================
Row
---------------------------------------------
### Time Series Graph for number of Victims recorded for each state of Australia from 2010-2019.
```{r}
#Creating time series chart.
stateList <- list(
list(
active = 1, x = -.125, type= 'buttons',
buttons = list(
list(
label = "ALL",
method = "update",
args = list(list(visible = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)))),
list(
label = "NSW",
method = "update",
args = list(list(visible = c( TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)))),
list(
label = "VIC",
method = "update",
args = list(list(visible = c(FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)))),
list(
label = "QLD",
method = "update",
args = list(list(visible = c(FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE)))),
list(
label = "SA",
method = "update",
args = list(list(visible = c( FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE)))),
list(
label = "WA",
method = "update",
args = list(list(visible = c( FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE)))),
list(
label = "TAS",
method = "update",
args = list(list(visible = c( FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE)))),
list(
label = "NT",
method = "update",
args = list(list(visible = c( FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE)))),
list(
label = "ACT",
method = "update",
args = list(list(visible = c( FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE))))
)
)
)
fig <- plot_ly(stateSpread) %>%
add_lines(x = ~Year, y = ~NSW, name = "NSW",
visible = "legendonly") %>%
add_lines(x = ~Year, y = ~VIC, name = "VIC",
visible = "legendonly" ) %>%
add_lines(x = ~Year, y = ~QLD, name = "QLD",
visible = "legendonly") %>%
add_lines(x = ~Year, y = ~SA, name = "SA",
visible = "legendonly") %>%
add_lines(x = ~Year, y = ~WA, name = "WA",
visible = "legendonly") %>%
add_lines(x = ~Year, y = ~TAS, name = "TAS",
visible = "legendonly") %>%
add_lines(x = ~Year, y = ~NT, name = "NT",
visible = "legendonly") %>%
add_lines(x = ~Year, y = ~ACT, name = "ACT",
visible = "legendonly") %>%
layout(
yaxis = list(zeroline = FALSE, title = "Count"),
xaxis = list(zeroline = FALSE, title = "Year"),
updatemenus= stateList) %>%
config(displayModeBar = FALSE)
fig
```
### Choropleth Map shows total number of victims for different parts of Australia from 2010-2019 combined.
```{r}
#Creating a choropleth map.
m <- ggplot(data = totalCount, aes(fill = total, lab = NAME)) + geom_sf() +
scale_fill_gradient(low = "white", high = "red") +
labs(
x = "Victim Records for Australia. (in Millions)",
fill = "Count (M)")+
theme_classic() + theme(axis.line = element_blank()) +
theme(axis.text = element_blank()) +
theme(axis.ticks = element_blank())
g <- ggplotly(m)
g
```
Row {data-height=300}
------------------------------------------------
### Total Incidents and Offence Types categorised by Sex of Victim from 2010-2019 in Australia.
```{r}
fig <- ggplot(test, aes(y = factor(Offence), x = Total, fill = Gender))+
geom_bar(stat = "identity", width = 0.2) +
labs(
x = "Total Number of Victims",
y = "")+
theme_minimal()
fig <- ggplotly(fig)
fig
```
### Total Incidents in Australia from 2010-2019.
```{r}
fig <- plot_ly(tc, x = ~Year, y = ~total, mode = 'lines+markers', type = 'scatter') %>%
layout(
xaxis = list(title = ""),
yaxis = list(title = ""))%>%
config(displayModeBar = FALSE)
fig
```
Source
===============================================
Row {data-width=600}
-----------------------------------------------
###
```{r}
valueBox(paste("Data Source : Australian Bureau of Statistics"),
caption ="Australian Bureau of Statistics: Recorded Crime - Victims, Australia. (2020, July 09). Retrieved from https://www.abs.gov.au/statistics/people/crime-and-justice/recorded-crime-victims-australia/latest-release#data-download on (2020, October 28).")
```