#| echo: FALSE knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-" )
ozroaddeaths is a package that pulls data from the Australian Road Deaths Database, run by the Bureau of Infrastructure, Transport and Regional Economics (BITRE). This provides basic details of road transport crash fatalities in Australia as reported by the police each month to the State and Territory road safety authorities. The details provided in the database fall into two groups:
The circumstances of the crash, for example, date, location, crash type
Some details regarding the persons killed, for example, age, gender and road user group.
You can install ozroaddeaths from github with:
#| label: gh-installation #| eval: false # install.packages("pak") pak::pak("njtierney/ozroaddeaths")
Or from the R Universe with:
#| label: r-universe #| eval: false install.packages("ozroaddeaths", repos = c("https://njtierney.r-universe.dev", "https://cloud.r-project.org"))
#| label: setup #| include: false #| fig-show: hide knitr::opts_chunk$set(fig.width=8, fig.height=5)
This data is taken from the Australian Road Deaths Database, which provides basic details of road transport crash fatalities in Australia as reported by the police each month to the State and Territory road safety authorities, obtained from: https://data.gov.au/dataset/ds-dga-5b530fb8-526e-4fbf-b0f6-aa24e84e4277/details?q=crash
Details provided in the database fall into two groups:
the circumstances of the crash, for example, date, location, crash type
some details regarding the persons killed, for example, age, gender and road user group.
The fatality data is updated every month. The heavy vehicle flags (for articulated truck, heavy rigid truck and bus involvement) are only updated each quarter, and are current to within two months. Information for heavy rigid truck involvement in crashes earlier than 2004 is incomplete. There is no day of the month for the data, so we have imputed this as the first of the month.
Data was available at URL as at 13th December 2019. Data is imported into R and cleaned by removing redundant date columns and transforming into a tidy format.
The Bureau of Infrastructure, Transport and Regional Economics has taken due care in preparing this information. However, noting that data have been provided by third parties, the Commonwealth gives no warranty as to the accuracy, reliability, fitness for purpose, or otherwise of the information.
Copyright
© Commonwealth of Australia, 2024
This work is copyright and the data contained in this publication should not be reproduced or used in any form without acknowledgement.
#| label: load-library #| message: false #| warning: false library(ozroaddeaths) library(dplyr) library(ggplot2) library(lubridate) library(ggridges)
#| label: load-data crashes <- oz_road_fatal_crash() fatalities <- oz_road_fatalities()
#| results: asis knitr::kable(dplyr::as_data_frame(names(crashes))) knitr::kable(head(crashes))
#| label: fatalities-first-look #| results: asis knitr::kable(dplyr::as_data_frame(names(fatalities))) knitr::kable(head(fatalities))
#| label: crash-plot-by-year #| width: 10 crash_plot <- ggplot(crashes, aes(x = year, fill = year)) + geom_line(stat = "count") + theme_minimal() + ggtitle("Annual number of fatal car accidents per year") crash_plot
#| label: crash-plot-by-year-and-state #| width: 10 crash_plot + scale_y_continuous(trans = "log2") + facet_wrap(~state) + ggtitle("Annual number of fatal car accidents per year and state", subtitle = "log2 scale" )
#| label: fatalities-plot-by-year #| width: 10 fatality_plot <- fatalities %>% mutate(year = lubridate::year(date_time)) %>% ggplot(aes(x = year, fill = year)) + geom_line(stat = "count") + theme_minimal() + ggtitle("Annual number of road fatalities") fatality_plot
#| label: fatalities-plot-by-age #| width: 10 fatality_plot <- fatalities %>% filter(gender != "Unspecified") %>% mutate(year = lubridate::year(date_time)) %>% ggplot(aes(x = age, fill = gender )) + geom_density() + facet_wrap(~gender) + theme_minimal() + ggtitle("Distribution of road fatalities by age 1989 to 2017") fatality_plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.