The goal of fars is to provide some functions to analyse data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System, which is a nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.
In the package there are 3 exemplificative files of how the data looks like and that can be used to have a better idea of how the functions work.
You can install the released version of fars from GitHub with:
install_github("veronicavedovetto/fars", build_vignettes = TRUE)
This is a basic example which shows you how to import one of the file with collected data and obtain a summary for the number of monthly accidents happened in two years:
library(fars)
#> Loading required package: dplyr
#> Warning: package 'dplyr' was built under R version 3.5.3
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#> Loading required package: magrittr
#> Warning: package 'magrittr' was built under R version 3.5.3
#> Loading required package: maps
#> Warning: package 'maps' was built under R version 3.5.3
#> Loading required package: readr
#> Warning: package 'readr' was built under R version 3.5.3
#> Loading required package: tidyr
#> Warning: package 'tidyr' was built under R version 3.5.3
#>
#> Attaching package: 'tidyr'
#> The following object is masked from 'package:magrittr':
#>
#> extract
fars_summarize_years(2013:2014, demo = TRUE)
#> # A tibble: 12 x 3
#> MONTH `2013` `2014`
#> <dbl> <int> <int>
#> 1 1 2230 2168
#> 2 2 1952 1893
#> 3 3 2356 2245
#> 4 4 2300 2308
#> 5 5 2532 2596
#> 6 6 2692 2583
#> 7 7 2660 2696
#> 8 8 2899 2800
#> 9 9 2741 2618
#> 10 10 2768 2831
#> 11 11 2615 2714
#> 12 12 2457 2604
demo = TRUE
will tell the function to use the data provided with the package as an example. If you want to use new downloaded data set it to FALSE (default value) and put the zipped files in the working directory.
You can also plot where accidents have happened with the following function:
fars_map_state(1, 2013, demo = TRUE)
You should indicate the number of the state and the year to be visualized.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.