The FARS package is very simple tool that helps to explor the data from FARS (Fatality Analysis Reporting System). The FARS package reads and summarize the data and map the locations of accidents.
The files are provided by the US National Highway Traffic Safety Administration (NHTSA) Fatality Analysis Reporting System (FARS). It lists the fatal vehicle crashes in the United States for each year. Check NHTSA website for more information https://www.nhtsa.gov/research-data/fatality-analysis-reporting-system-fars.
Annual accident data should be downloaded from FARS website and saved in the current working directory. Libraries that wich functions will be used in FARS package:
# Libraries library(dplyr) library(readr) library(magrittr) library(tidyr) library(maps) library(graphics)
If you want to explore fatality data for a selected year, use the fars_read_years() function and input the year you need to research.
# year 2013 Data2013<-fars_read_years(2013) Data2013
This function returns tbl_df (the tidyverse data frame) having the month and a year for each fatal accident. This data can be used only for counting the number of accidents by month.
If you need to explore the data for multiple years, you need to enter a vector of years as the argument for the fars_read_years() function.
# years 2013-2015 Data2013_15<-fars_read_years(2013:2015) Data2013_15
In this case the this returns also a list of tbl_dfs. Each data frame will show the month and year for each fatality.
To make a summary of fatalities use fars_summarize_years() function. You need to enter a year or a vector of years as the argument of this function.
FARS_Summary<-fars_summarize_years(2013:2015) FARS_Summary
The function will return the number of accidents by month and year.
To map accidents use fars_map_state() function. As an argument add a year or years and state ID number. This function displays a plot with a state map including the accidents for the selected year.
# Map accident locations for 2013 for state number 42, Pensylvania fars_map_state(state.num = 42, year = 2015)
For a list of the state ID numbers, see page 26 "Key data elements" of the FARS Analytical User's Guide (2015). http://www.nber.org/fars/ftp.nhtsa.dot.gov/fars/FARS-DOC/Analytical%20User%20Guide/USERGUIDE-2015.pdf
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.