Introduction

This vignette shows how to use the fars package. The fars package has functions to read the data downloaded from the Fatality Analysis Reporting System, summarize the data, and map the locations of accidents.

Installation

You can install this package directly from GitHub.

install.packages("devtools")
devtools::install_github("faizan-khan-iit/fars")

Downloading Data

Go to the FARS website and download the data in the current working directory. A sample file has been included in the package as an example in inst/extdata.

file_2015 <- system.file("extdata", "accident_2015.csv.bz2", package = "fars")

Reading the data

To read the downloaded data files, use the fars_read_years() function. Multiple years' data can also be read at once by passing a vector containing multiple values.

# Read data for year 2015
fars_read_years(c(2015))

# Read data for years 2010 to 2014
fars_read_years(c(2010:2014))

We can see the accident cases for every month for the years provided.

Summarized data

Use the fars_summarize_years() to read and summarize the data for the years provided.

# Summarize data for year 2015
fars_summarize_years(c(2015))

The function returns a tibble with the number of cases per month for a given year.

Plot the locations of accident on a map

Use fars_map_state() to plot the locations for the accidents for a particular state, defined by state.num. The state.num values are according to the FARS website.

# Plot accident locations for 2015 for state number 15, Hawaii
fars_map_state(state.num = 15, year = 2015)


faizan-khan-iit/fars documentation built on May 16, 2019, 9:59 a.m.