knitr::opts_chunk$set(echo = FALSE, message = FALSE, collapse = T, comment = "#>") library(sofars2) library(dplyr) library(maps) library(graphics) library(tidyr)
This package consists of function which can be used to read, analyze and map FARS( Fatality Analysis Reporting System ) data. FARS is a nationwide census providing NHTSA, Congress and the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.
The following functions are included in the package: fars_read() make_filename() fars_read_years() fars_summarize_years() fars_map_state() The examples use data from FARS, years 2013-2015, that can be found in the package directory under \extdata folder.
This function read data from a file path provided as an argument and returns a tibble with loaded data
filename <- system.file("extdata", "accident_2013.csv.bz2", package = "sofars2") fars_read(filename)
This function creates a filename with the year number which is passed as an argument.
make_filename(2013)
This function returns a pivot table with number of accidents per year and month.
#system.file("extdata", package = "sofars2") #system.file("extdata") #getwd() setwd("../inst/extdata") #getwd() fars_summarize_years(2013)
This function takes a state index and year as arguments and returns a map of the state with accident locations plotted.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.