knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
devtools::load_all()
This package allows to summarise and plot US accident data through two main wrapper functions:
fars_summarize_years() counts the number observations in each month of the specified year.fars_map_state() plots the accident locations on a map of the specified state and year.The package comes with a couple of helper functions that enable you to read accident files from several years. They are also used under the hood of the two main wrapper functions.
make_filename() creates a filename following the pattern "accident_YEAR.csv.bz2", e.g. accident_2013.csv.bz2.fars_read() reads a csv under the specified file path.fars_read_years() combines make_filename() and fars_read() and reads CSVs of all years specified. Note that the CSVs need to follow the pattern "accident_YEAR.csv.bz2" and they need to be located in the working directory.fars_summarize_years() uses fars_read_years() under the hood to read data of all years specified and then counts the number observations per month.
# Summarise Multiple Years fars_summarize_years(years = c("2013", "2014", "2015"))
fars_map_state() uses make_filename() fars_read() under the hood to create and read the path of the csv for the specified year. A state of interest needs to be selected via argument state.num and then the accidents of this state are plotted on a map. Below the accidents for state number "13" in 2013 are plotted.
# Summarise Multiple Years fars_map_state(state.num = 13, year = "2013")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.