Summary of Accidents

Column

Total Number of Accidents in Different Regions of Victoria from 2014-2019

Trend of Road Crashes

Column

Total Number of Accidents against each month[2014-2019]

========================================================================

Column

Crashes by Day of Week


Deaths throughout Years


Types of Crashes and Deaths due to them

Factors of Road Crashes and Deaths

Column

Number of Accidents and Number of Fatalities against each month due to Alcohol


Number of Accidents and Number of Fatalities against each month in Different Speed Zone

Column

Number of Accidents and Number of Fatalities against each month due to Light Conditions


Age Groups involved in Crash

Story and References

Story:

From the analysis of Victoria’s Road Crash data from 2014 till 2019, we can understand that most of the crashes happened in Metropolitan South East and North West regions of Victoria. We can see a decreasing trend in the total number of accidents in 2019 compared to that in 2014 with Friday being the day of the week with most of the accidents. Collision with another vehicle is the major reason for the accidents with most of them happening during day time with 30 to 60 years old age group being the major individuals involved. Even though alcohol did not play a major role in the number of accidents, we can conclude that higher speeds (greater than 90 km/hr) caused most of the accidents. Hence, drive slowly and save not just your life but also the surrounding Victorians’ lives on road.

References:

  1. Discover.data.vic.gov.au. 2021. Road Crashes for five Years - Victoria - Victorian Government Data Directory. [online] Available at: https://discover.data.vic.gov.au/dataset/road-crashes-for-five-years-victoria [Accessed 18 October 2021].

    1. [online] Available at: https://discover.data.vic.gov.au/dataset/speed-zonedata [Accessed 19 October 2021].
  2. Plotly.com. 2021. Plotly R Graphing Library. [online] Available at: https://plotly.com/r/ [Accessed 26 October 2021].

  3. Vicroads.vic.gov.au. 2021. Home Page : VicRoads. [online] Available at: https://www.vicroads.vic.gov.au/ [Accessed 26 October 2021].

  4. Data.vicroads.vic.gov.au. 2021. Metadata Capture & Discovery Tool. [online] Available at: https://data.vicroads.vic.gov.au/metadata/Crashes_Last_Five_Years%20-%20Open%20Data.html [Accessed 18 October 2021].

---
title: "Victoria Road Crash Report 2014-2019"
author:Shristi Chavhan ,StudentID: s3822713
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
library(ggplot2)
library(dplyr)
library(readr)
library(tidyverse)
library(lubridate)
library(plyr)
library(plotly)
library(RColorBrewer)

#importing data
file <- read_csv("file.csv")
#Checking date format
is.Date(file$ACCIDENT_D)
#Drop na values from dataset
drop_na(file)
```

Summary of Accidents
====================================================================

Column {data-width=850}
-----------------------------------------------------------------------

###  Total Number of Accidents in Different Regions of Victoria from 2014-2019

```{r}
file_result1 <- file %>% group_by(REGION_NAM) %>% summarise(count=n())
file_result1$REGION_NAM <- factor(file_result1$REGION_NAM , levels = unique(file_result1$REGION_NAM)[order(file_result1$count )])
p1 <-plot_ly() %>% add_trace(data= file_result1, type ="bar",colors="Blues",
                             y =file_result1$REGION_NAM,
                             x = file_result1$count,
                             color = file_result1$REGION_NAM,
                             hovertemplate = paste('
Region Name: %{y}
', 'Total Number of Accidents: %{x: .2d}
') ) %>% layout(title = "Accidents in Different Regions of Victoria", yaxis = list( zeroline = FALSE ), xaxis = list(title = "Number of Accidents", zeroline = FALSE)) p1 ``` Trend of Road Crashes ======================================================================== Column {data-width=900} ----------------------------------------------------------------------- ### Total Number of Accidents against each month[2014-2019] ```{r} file_result <- file %>% group_by(ACCIDENT_D,FATALITY) %>% summarise(count=n()) dataAggrerate <- file_result %>% mutate(year = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%Y"), month_name = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%b"), month_number = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%m"), month_year = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%b %Y"), full_date = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%d/%m/%Y"), ) new_datasert <- dataAggrerate[ ,c(2,3,4,5,6,7)] dataAggrerate_total <- aggregate(new_datasert$count, by=list(MonthYear=new_datasert$month_year,month_number=new_datasert$month_number,year=new_datasert$year ), FUN=sum) dataAggrerate_total <- dataAggrerate_total[ ,c(1,4)] p2.1 <- plot_ly(dataAggrerate_total, type = 'scatter', mode = 'lines+markers')%>% add_trace(x = ~MonthYear, y = ~x, hovertemplate = paste('
Month and Year: %{x}
', 'Total Number of Accidents in a Month: %{y: .2d}
') )%>% layout(title = "Victoria Road Crashes 2014-2019", yaxis = list(zeroline = FALSE,title = 'Total Number Of Accidents'), xaxis = list(zeroline = FALSE,title = 'Month and Year'),showlegend = F) p2.1 <- p2.1 %>% layout( xaxis = list(zerolinecolor = '#ffff', zerolinewidth = 2, gridcolor = 'ffff'), yaxis = list(zerolinecolor = '#ffff', zerolinewidth = 2, gridcolor = 'ffff'), plot_bgcolor='#e5ecf6', width=1200) p2.1 ``` ======================================================================== Column {data-width=450} ----------------------------------------------------------------------- ### Crashes by Day of Week ```{r} file_result_week <- file %>% group_by(DAY_OF_WEE) %>% summarise(count=n()) file_result_week<-na.omit(file_result_week) file_result_week$DAY_OF_WEE <- factor(file_result_week$DAY_OF_WEE,levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")) names(file_result_week)[2] <- "NumberOfAccidents" #View(file_result_week) p4 <- plot_ly(data = file_result_week, x = ~DAY_OF_WEE, y = ~NumberOfAccidents, type = "bar", hovertemplate = paste('
Day of the Week: %{x}
', 'Number of Accidents: %{y: .2d}
'), colors = c("#67a9cf")) %>% layout(title="Number of Acccidents by Day of Week",yaxis = list(zeroline = FALSE, title = "Number of Accidents"), xaxis = list(zeroline = FALSE, title = "Day of Week")) p4 ``` ----------------------------------------------------------------------- ### Deaths throughout Years ```{r} file_result_deadth <- file %>% group_by(ACCIDENT_D,FATALITY) file_result_deadth <- file_result_deadth[,c(6,28)] file_result_deadth <- na.omit(file_result_deadth) dataAggrerate_year <- file_result_deadth %>% mutate(year = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%Y"), month_name = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%b"), month_number = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%m"), month_year = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%b %Y"), ) new_datasert_year <- dataAggrerate_year[ ,c(2,3)] file_result_deadth <- new_datasert_year %>% group_by(year) %>% summarise(count=sum(FATALITY)) names(file_result_deadth)[2] <- "NumberOfDeadths" p6 <- plot_ly(data = file_result_deadth,mode = 'lines+markers',type = 'scatter',x=~year,y=~NumberOfDeadths,text = ~NumberOfDeadths) %>% add_trace(hovertemplate = paste('
Year: %{x}
', 'Number Of Total Deaths: %{y: .2d}
') )%>% layout(title = "Deaths throughout Years [2014-2019]",showlegend = FALSE, yaxis = list(zeroline = FALSE,title = 'Total Number of Deaths'), xaxis = list(zeroline = FALSE,title = 'Year')) p6 ``` ----------------------------------------------------------------------- ### Types of Crashes and Deaths due to them ```{r} file_result_week2.3 <- file %>% group_by(ACCIDENT_T) %>% summarise(count=n()) file_result_week2.3<-na.omit(file_result_week2.3) file_result_week2.3$ACCIDENT_T <- factor(file_result_week2.3$ACCIDENT_T , levels = unique(file_result_week2.3$ACCIDENT_T )[order(file_result_week2.3$count )]) file_result_week2.3 <-file_result_week2.3[order(file_result_week2.3$count),] p2.3 <- plot_ly(data = file_result_week2.3, y = ~ACCIDENT_T, x = ~count, type = "bar", colors = c("#67a9cf"), hovertemplate = paste('
Cause of Accident: %{y}
', 'Total Number of Accidents: %{x: .2d}
') ) %>% layout(title="Different Accidents Types",yaxis = list(zeroline = FALSE,showticklabels = TRUE,title=FALSE), xaxis = list(zeroline = FALSE, title = "Number of Accidents",showticklabels = TRUE)) p2.3 ``` Factors of Road Crashes and Deaths ======================================================================== Column {data-width=450} ----------------------------------------------------------------------- ### Number of Accidents and Number of Fatalities against each month due to Alcohol ```{r} file_result_3.1 <- file %>% group_by(ACCIDENT_D,FATALITY,ALCOHOL_RE) %>% summarise(count=sum(FATALITY)) file_result_3.1<-na.omit(file_result_3.1) month_year_3.1Dataset <- file_result_3.1 %>% mutate( month_name = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%b") ) month_year_3.1Dataset <- month_year_3.1Dataset[ ,c(2,3,5)] month_year_3.1Dataset_final <- aggregate(month_year_3.1Dataset$FATALITY, by=list(month_name=month_year_3.1Dataset$month_name, ALCOHOL_RE=month_year_3.1Dataset$ALCOHOL_RE), mean) month_year_3.1Dataset_final$ALCOHOL_RE[month_year_3.1Dataset_final$ALCOHOL_RE == "Yes"] <- "Alcoholic" month_year_3.1Dataset_final$ALCOHOL_RE[month_year_3.1Dataset_final$ALCOHOL_RE == "No"] <- "Non-Alcoholic" month_year_3.1Dataset_final$month_name <- factor(month_year_3.1Dataset_final$month_name,levels=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")) p3.1 <-plot_ly() %>% add_trace(data= month_year_3.1Dataset_final, type ="bar", y = month_year_3.1Dataset_final$x, x = month_year_3.1Dataset_final$month_name, text = month_year_3.1Dataset_final$ALCOHOL_RE, color = month_year_3.1Dataset_final$ALCOHOL_RE, hovertemplate = paste('
Mean of Fatalities: %{y: .2f}
', 'Month: %{x}
','%{text}
') ) %>% layout(title = "Fatalities due to Alcohol",height= 300,widht=300, xaxis = list(title = "Months ", zeroline = FALSE), yaxis = list(title = "Mean of Fatalities", zeroline = FALSE)) p3.1 ``` ----------------------------------------------------------------------- ### Number of Accidents and Number of Fatalities against each month in Different Speed Zone ```{r} file_result_3.2 <- file %>% group_by(ACCIDENT_D,FATALITY,SPEED_ZONE) %>% summarise(count=sum(FATALITY)) file_result_3.2<-na.omit(file_result_3.2) file_result_3.2$SPEED_ZONE[file_result_3.2$SPEED_ZONE == "100 km/hr" | file_result_3.2$SPEED_ZONE == "90 km/hr" | file_result_3.2$SPEED_ZONE == "110 km/hr" ] <- (("90-110km/hr")) file_result_3.2$SPEED_ZONE[file_result_3.2$SPEED_ZONE == "70 km/hr" | file_result_3.2$SPEED_ZONE == "75 km/hr" | file_result_3.2$SPEED_ZONE == "80 km/hr" ] <- (("60-90km/hr")) file_result_3.2$SPEED_ZONE[file_result_3.2$SPEED_ZONE == "30 km/hr" | file_result_3.2$SPEED_ZONE == "40 km/hr" | file_result_3.2$SPEED_ZONE == "50 km/hr"| file_result_3.2$SPEED_ZONE == "60 km/hr" ] <- (("30-60km/hr")) month_year_3.2Dataset <- file_result_3.2 %>% mutate( month_name = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%b") ) month_year_3.2Dataset_final <- aggregate(month_year_3.2Dataset$FATALITY, by=list(month_name=month_year_3.2Dataset$month_name, SPEED_ZONE=month_year_3.2Dataset$SPEED_ZONE), mean) month_year_3.2Dataset_final$month_name <- factor(month_year_3.2Dataset_final$month_name,levels=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")) l <- list( font = list( family = "sans-serif", size = 9 ), orientation = "v", # show entries horizontally yanchor = "left" # use center of legend as anchor ) p3.2 <-plot_ly() %>% add_trace(data= month_year_3.2Dataset_final, type ="bar",colors = "Blues", y = month_year_3.2Dataset_final$x, x = month_year_3.2Dataset_final$month_name,text= month_year_3.2Dataset_final$SPEED_ZONE, color = month_year_3.2Dataset_final$SPEED_ZONE, hovertemplate = paste('
Mean of Fatalities: %{y: .2f}
', 'Month: %{x}
' ,'Speed: %{text}
') ) %>% layout(title = list(text = "Fatalities due to Speed"),height= 300,widht=500, xaxis = list(title = "Months ", zeroline = FALSE), yaxis = list(title = "Mean of Fatalities", zeroline = FALSE),legend = l) p3.2 ``` Column {data-width=450} ----------------------------------------------------------------------- ### Number of Accidents and Number of Fatalities against each month due to Light Conditions ```{r} file_result_3.3 <- file %>% group_by(ACCIDENT_D,FATALITY,LIGHT_COND) %>% summarise(count=sum(FATALITY)) file_result_3.3<-na.omit(file_result_3.3) month_year_3.3Dataset <- file_result_3.3 %>% mutate( month_name = format(as.Date(ACCIDENT_D, format="%d/%m/%Y"),"%b") ) #View(month_year_3.3Dataset_final) month_year_3.3Dataset_final <- aggregate(month_year_3.3Dataset$FATALITY, by=list(month_name=month_year_3.3Dataset$month_name, LIGHT_COND=month_year_3.3Dataset$LIGHT_COND), mean) month_year_3.3Dataset_final$month_name <- factor(month_year_3.3Dataset_final$month_name,levels=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")) l <- list( font = list( family = "sans-serif", size = 9 ), orientation = "v", # show entries horizontally yanchor = "left" # use center of legend as anchor ) month_year_3.3Dataset_final$LIGHT_COND[month_year_3.3Dataset_final$LIGHT_COND=="Unk."] <- "Unknown" p3.3 <-plot_ly() %>% add_trace(data= month_year_3.3Dataset_final, type ="bar",colors="Blues", y = month_year_3.3Dataset_final$x, x = month_year_3.3Dataset_final$month_name, color = month_year_3.3Dataset_final$LIGHT_COND, text = month_year_3.3Dataset_final$LIGHT_COND, hovertemplate = paste('Mean of Fatalities: %{y: .2f}
', 'Month: %{x}
' ,'Light Condition: %{text}
' )) %>% layout(title = "Fatalities due to Light Conditions",height= 300,widht=450,legend = l, xaxis = list(title = "Months ", zeroline = FALSE), yaxis = list(title = "Mean of Fatalities", zeroline = FALSE)) p3.3 ``` ----------------------------------------------------------------------- ### Age Groups involved in Crash ```{r} file_result_3.4 <- file %>% select(YOUNG_DRIV,OLD_DRIVER,DRIVER) file_result_3.4<-na.omit(file_result_3.4) numberyoungdriver <- c(sum(file_result_3.4$YOUNG_DRIV)) numberolddriver <- c(sum(file_result_3.4$OLD_DRIVER)) totaldriver <- c(sum(file_result_3.4$DRIVER)) unknownagedriver <- c(totaldriver - sum(numberolddriver+numberyoungdriver) ) driver_df <- data.frame(numberyoungdriver,numberolddriver,unknownagedriver) %>% gather() names(driver_df)[1] <- "NoOfDriver" driver_df[driver_df == "numberyoungdriver"] <- "18 to 25 years" driver_df[driver_df == "numberolddriver"] <- "65+ years" driver_df[driver_df == "unknownagedriver"] <- "30 to 60 years" #View(driver_df) figure<-plot_ly() %>% add_trace( driver_df, labels =driver_df$NoOfDriver , values =driver_df$value , type = 'pie',colors = "Blues" ) %>% layout(title = "Accidents by Age of the Driver",height= 300,widht=300,colors="Set3", xaxis = list(title = "Accidents by Age of the Driver", zeroline = FALSE ,showgrid = TRUE,showticklabels = TRUE), yaxis = list(title = "Age Group", zeroline = FALSE,showgrid = TRUE,showticklabels = TRUE)) figure ``` Story and References {data-orientation=columns} =========================================== Story: From the analysis of Victoria's Road Crash data from 2014 till 2019, we can understand that most of the crashes happened in Metropolitan South East and North West regions of Victoria. We can see a decreasing trend in the total number of accidents in 2019 compared to that in 2014 with Friday being the day of the week with most of the accidents. Collision with another vehicle is the major reason for the accidents with most of them happening during day time with 30 to 60 years old age group being the major individuals involved. Even though alcohol did not play a major role in the number of accidents, we can conclude that higher speeds (greater than 90 km/hr) caused most of the accidents. Hence, drive slowly and save not just your life but also the surrounding Victorians' lives on road. References: 1. Discover.data.vic.gov.au. 2021. Road Crashes for five Years - Victoria - Victorian Government Data Directory. [online] Available at: [Accessed 18 October 2021]. 2. 2021. [online] Available at: [Accessed 19 October 2021]. 3. Plotly.com. 2021. Plotly R Graphing Library. [online] Available at: [Accessed 26 October 2021]. 4. Vicroads.vic.gov.au. 2021. Home Page : VicRoads. [online] Available at: [Accessed 26 October 2021]. 4. Data.vicroads.vic.gov.au. 2021. Metadata Capture & Discovery Tool. [online] Available at: [Accessed 18 October 2021].