Introduction

Source: Insurance Journal, 2021

Source: Insurance Journal, 2021

What’s the trend been for road accidents in Victoria?


Looking back from 2014 to 2019, road accidents in Victoria have been reduced to some extent. However, the number of crashes occuring in a single day have not quite changed and it’s still dreadful. If we look carefully at the patterns where these accidents happen, it’s more obvious.

Where were the accident hotspots?


City of Melboure and it’s urban suburbs have been the hotspots of crashes. Despite of the planned roads with traffic signals at almost hundred meters apart, accidents have been inevitable due to majority of people commuting from outer suburbs to the city. I analysed the time to see if this holds true in Melbourne and the results were surprising.

Rush hours, busy traffic and more accidents?


No doubt, it’s 9:00 am and 6:00 pm where most of the accidents have had happened. Although, the majority collision were minor, there have been serious injuries and deaths.

But, Was 2019 really bad?


With the close comparison on causes of accidents between 2018 and 2019, the latter year shows some good safety measures were applied reducing the number of collission and hitting a pedestrian by 50%. However, the other 50% is still concerning when it comes to lives of people.

Can we do something about it?


Most accidents happen on the road lanes followed by intersections. A little cautiousness is these areas could potentially reduce the number of injuries and deaths. Accidents are unpredictable however, knowing where most mishaps occurs, one can be more careful to avoid such situations.

Conclusion

Source

Source

References

[1] J. Baglin, “Data Visualisation: From theory to Practice”, Dark-star-161610.appspot.com, 2020. [Online]. Available: https://dark-star-161610.appspot.com/secured/_book/spatial-data.html. [Accessed: 04- Jun- 2021].

[2] Data: “Road Crashes for five Years - Victoria”, Vicroadsopendata-vicroadsmaps.opendata.arcgis.com, 2021. [Online]. Available: https://vicroadsopendata-vicroadsmaps.opendata.arcgis.com/datasets/vicroadsmaps::road-crashes-for-five-years-victoria/about. [Accessed: 04- Jun- 2021].

[3] “6 Tips on Accident Prevention”, Len Dubois Trucking, 2021. [Online]. Available: https://lenduboistrucking.com/blog/6-tips-on-accident-prevention/. [Accessed: 05- Jun- 2021].

[4] A. Levin, “Safety Advocates Frustrated that Accident-Prevention Technologies Remain Optional”, Insurance Journal, 2021. [Online]. Available: https://www.insurancejournal.com/news/national/2016/11/15/432279.htm. [Accessed: 08- Jun- 2021].

[5]→, “RStudio Community”, RStudio Community, 2021. [Online]. Available: https://community.rstudio.com/. [Accessed: 08- Jun- 2021].

[6] “R Markdown Format for Flexible Dashboards”, Pkgs.rstudio.com, 2021. [Online]. Available: hUttps://pkgs.rstudio.com/flexdashboard/. [Accessed: 07- Jun- 2021].

---
title: "More than 190 lives were lost in Victorian road. How bad was 2019?"
output: 
  flexdashboard::flex_dashboard:
    storyboard: true
    social: menu
    source: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(tidyverse)
library(dplyr)
library(rgeos)
library(maptools)
library(ggmap)
library(broom)
vic_roads <- read_csv('Road_Crashes_for_five_Years_-_Victoria.csv')
```
```{r, include=FALSE}
vic.lga.shp <- readShapeSpatial("data/vmlite_lga_cm.shp")
lga.shp.f <- tidy(vic.lga.shp, region = "lga_name")
lga.shp.f$LGA_NAME <-lga.shp.f$id


vic.lga.shp.simp1 <- gSimplify(vic.lga.shp, tol = .01, topologyPreserve=TRUE)
vic.lga.shp.simp1 <- SpatialPolygonsDataFrame(vic.lga.shp.simp1,
                                              data=vic.lga.shp@data)
lga.shp.f.simp1 <- tidy(vic.lga.shp.simp1, region = "lga_name")
print(paste(nrow(lga.shp.f.simp1),"rows"))

```
```{r,include = FALSE}
lga.shp.f.simp1$LGA_NAME <- lga.shp.f.simp1$id

road_vic <- vic_roads %>% group_by(LGA_NAME) %>% summarise(total_accident = sum(INJ_OR_FATAL,na.rm = T))
merge.lga.profiles2<-merge(lga.shp.f.simp1, road_vic,
                          by="LGA_NAME", all.x=TRUE)

choro.data.frame2<-merge.lga.profiles2[order(merge.lga.profiles2$order), ]


```
### Introduction

![Source: Insurance Journal, 2021](fraud-accident-580x385.jpg)

### What's the trend been for road accidents in Victoria? 

```{r,include = FALSE}

library(leaflet)
library(mapproj)
library(plotly)
library(htmlwidgets)
library(htmltools)


#choro.data.frame2$total_accident[is.na(choro.data.frame2$total_accident)]<- "N/A"
#choro.data.frame2 <- choro.data.frame2 %>% filter(!is.na(total_accident))
```

```{r}



trend <- vic_roads %>% group_by(ACCIDENT_DATE) %>% summarise(count = sum(INJ_OR_FATAL))

p1 <- plot_ly(data = trend) %>% 
  
  add_trace(x = ~ACCIDENT_DATE, y = ~count, mode = 'lines') %>% 
  
  layout(yaxis = list(zeroline = FALSE),
         xaxis = list(zeroline = FALSE, rangeslider = list(type = "date")),
         title = "Victorian Road Accidents from 2014 -2019")

p1

```

***

Looking back from 2014 to 2019, road accidents in Victoria have been reduced to some extent. However, the number of crashes occuring in a single day have not quite changed and it's still dreadful. If we look carefully at the patterns where these accidents happen, it's more obvious.


### Where were the accident hotspots?

```{r}
options(repr.plot.width = 10, repr.plot.height =10)
ggplot(data = choro.data.frame2,
             aes(x = long, y = lat, group = group,
                 fill = total_accident)) + geom_polygon(color = "black", size = 0.25) +
  coord_map() +
  scale_fill_distiller(name = "Injured or Fatal accidents",guide = "legend",
                    palette = "YlOrRd",direction = 1) +
  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=" Melbourne: the major hotspot in Victoria ")

```


***

City of Melboure and it's urban suburbs have been the hotspots of crashes. Despite of the planned roads with traffic signals at almost hundred meters apart, accidents have been inevitable due to majority of people commuting from outer suburbs to the city. I analysed the time to see if this holds true in Melbourne and the results were surprising.


### Rush hours, busy traffic and more accidents?

```{r}

melbourne <- vic_roads %>% filter(LGA_NAME == 'MELBOURNE')
melbourne$ACCIDENT_TIME <- format(round(strptime(melbourne$ACCIDENT_TIME, format="%H:%M"), units="hours"), format="%H:%M")
melbourne <- melbourne %>% mutate(severity = ifelse(SEVERITY =="Fatal accident"| SEVERITY=="Serious injury accident","Serious and Fatal","Minor"))
time_total <- melbourne %>% group_by(ACCIDENT_TIME,severity) %>% summarise(total = sum(TOTAL_PERSONS))%>% arrange(desc(total))

#time_total <- melbourne %>% group_by(ACCIDENT_TIME) %>% transmute(severity, percent = TOTAL_PERSONS/sum(TOTAL_PERSONS)*100)



p3<- ggplot(time_total,aes(x = ACCIDENT_TIME,y=total,fill = severity))+ geom_bar(stat = "identity",position = "stack")+ theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) + ggtitle("Hours when most crashes have occurred") + ylab("Injuries") + xlab("Time") + theme(plot.title = element_text(hjust = 0.5))+ scale_fill_discrete(name = "Severity")

p3

```

***

No doubt, it's 9:00 am and 6:00 pm where most of the accidents have had happened. Although, the majority collision were minor, there have been serious injuries and deaths. 

### But, Was 2019 really bad?

```{r}
melbourne$year <- as.character(format(melbourne$ACCIDENT_DATE,'%Y'))
prev <- melbourne %>% filter(year == '2018' | year == '2019')
change <- prev %>% group_by(year,ACCIDENT_TYPE) %>% summarise(total = sum(INJ_OR_FATAL,na.rm=T)) %>% arrange(desc(total))
change$ACCIDENT_TYPE <- as.factor(change$ACCIDENT_TYPE)

p4 <- change %>% mutate(type = fct_reorder(ACCIDENT_TYPE,total)) %>% ggplot(aes(x = type,y = `total`,fill = factor(year,levels = c("2019","2018")),label = total)) + geom_bar(stat = "identity",position = "dodge")+ xlab("Accident Type") + ylab("Total Injuries")+coord_flip()+ scale_fill_discrete(name ="Year") + ggtitle("Victorians have become cautious")    + theme(plot.title = element_text(hjust = 0.5))


p4

```

***

With the close comparison on causes of accidents between 2018 and 2019, the latter year shows some good safety measures were applied reducing the number of collission and hitting a pedestrian by 50%. However, the other 50% is still concerning when it comes to lives of people.

###  Can we do something about it?

```{r}

where <- melbourne %>% group_by(ROAD_GEOMETRY) %>% summarise(total = sum(INJ_OR_FATAL))
bar_colours <- c("#99000d","#cc4c02","#cc4c02","#99000d","#cc4c02","#99000d","#cc4c02","#cc4c02")
ggplot(where,aes(x = reorder(ROAD_GEOMETRY,total),y = total,fill = bar_colours)) + geom_bar(stat = "identity") + coord_flip() + xlab(" ") + ylab("Accidents") + ggtitle("Places where we need to be careful")+ theme(plot.title = element_text(hjust = 0.5))+ theme(legend.position="none")
```

***

Most accidents happen on the road lanes followed by intersections. A little cautiousness is these areas could potentially reduce the number of injuries and deaths. Accidents are unpredictable however, knowing where most mishaps occurs, one can be more careful to avoid such situations. 

### Conclusion

![Source](Accident-Prevention-Photo-001.jpg)

### References

[1] J. Baglin, "Data Visualisation: From theory to Practice", Dark-star-161610.appspot.com, 2020. [Online]. Available: https://dark-star-161610.appspot.com/secured/_book/spatial-data.html. [Accessed: 04- Jun- 2021].

[2] Data: "Road Crashes for five Years - Victoria", Vicroadsopendata-vicroadsmaps.opendata.arcgis.com, 2021. [Online]. Available: https://vicroadsopendata-vicroadsmaps.opendata.arcgis.com/datasets/vicroadsmaps::road-crashes-for-five-years-victoria/about. [Accessed: 04- Jun- 2021].

[3] "6 Tips on Accident Prevention", Len Dubois Trucking, 2021. [Online]. Available: https://lenduboistrucking.com/blog/6-tips-on-accident-prevention/. [Accessed: 05- Jun- 2021].

[4] A. Levin, "Safety Advocates Frustrated that Accident-Prevention Technologies Remain Optional", Insurance Journal, 2021. [Online]. Available: https://www.insurancejournal.com/news/national/2016/11/15/432279.htm. [Accessed: 08- Jun- 2021].

[5]→, "RStudio Community", RStudio Community, 2021. [Online]. Available: https://community.rstudio.com/. [Accessed: 08- Jun- 2021].

[6] "R Markdown Format for Flexible Dashboards", Pkgs.rstudio.com, 2021. [Online]. Available: hUttps://pkgs.rstudio.com/flexdashboard/. [Accessed: 07- Jun- 2021].