fars package reads and plots Fatality Analysis Reporting System (FARS) data from the National Highway Traffic Safety Administration.
FARS is a nationwide census, providing the American public yearly data, regarding fatal injuries suffered in motor vehicle traffic crashes.
library(farsdata)
library(maps)Data files included within the package are:
list.files(system.file("extdata", package = "farsdata"))## [1] "accident_2013.csv.bz2" "accident_2014.csv.bz2" "accident_2015.csv.bz2"
make_filenameThis function returns file name and path to the data files:
yr <- 2015
make_filename(yr)## [1] "accident_2015.csv.bz2"
fars_read_yearsAncillary function used by fars_summarize_years
fars_read_years(2013)## [[1]]
## # A tibble: 30,202 x 2
## MONTH year
## <int> <dbl>
## 1 1 2013
## 2 1 2013
## 3 1 2013
## 4 1 2013
## 5 1 2013
## 6 1 2013
## 7 1 2013
## 8 1 2013
## 9 1 2013
## 10 1 2013
## # ... with 30,192 more rows
fars_summarize_yearsThis function summarizes yearly accidents data, by month.
plot(fars_summarize_years(2015))fars_summarize_years(c(2015, 2014))## # A tibble: 12 x 3
## MONTH `2014` `2015`
## <int> <int> <int>
## 1 1 2168 2368
## 2 2 1893 1968
## 3 3 2245 2385
## 4 4 2308 2430
## 5 5 2596 2847
## 6 6 2583 2765
## 7 7 2696 2998
## 8 8 2800 3016
## 9 9 2618 2865
## 10 10 2831 3019
## 11 11 2714 2724
## 12 12 2604 2781
fars_map_stateThe function displays a state map plot including accidents location by year
state_num <- 49 # Utah
yr <- 2014
fars_map_state(state_num, yr)