library(fars) library(dplyr) library(maps)
The package provide functions used for sumarizing data from FARS - Fatality Analysis Reporting System
The package required dplyr and maps installed beforehand
install.packages("dplyr") install.packages("maps")
The package is currently not in CRAN but you could download from Github
devtools::install_github("ThoDuyNguyen/fars")
library(fars) library(dplyr) library(maps)
We will use data from FARS, years 2013-2015, that can be found in the package directory under \extdata folder in the example.
fars_read read data from a file path provided as an argument. It returns a tibble with loaded data:
filename <- system.file("extdata/accident_2014.csv.bz2", package = "fars") fars_read(filename)
fars_summarize_years takes a vector or list of years (numeric/integer values) as an argument and returns a pivot table with number of accidents per year and month.
setwd(system.file("extdata", package = "fars")) fars_summarize_years(2013:2014)
fars_map_state takesstate index and year as arguments and returns a plot of the state with accident locations. The state indices need to correspond available indeces from the data set.
setwd(system.file("extdata", package = "fars")) fars_map_state(45, 2014)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.