knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This package includes some useful function to analyze the data in FARS that were
fars_read
: Read data from FARSfars_map_state
: Visualize the accidents in the US mapfars_read_years
: Read FARS data filesfars_summarize_years
: Summarize the number of observations by yearmake_filename
: Make file nameThrough fars_read
, we can read the FARS data that was saved by csv file with ".bz2" extension.
library(fars) file <- system.file("exdata", "accident_2015.csv.bz2", package = "fars") data <- fars_read(file) head(data)
The fars_summarize_years
can return the pivot table with the number of monthly accident cases (row) and the defined year(s) (column). Here the input parameter should be a numeric vector.
setwd(system.file("exdata", package = "fars")) fars_summarize_years(2013:2015)
The fars_map_state
returns a map with the plot of the state with accident locations. The State index was defined from 1 to 56.
setwd(system.file("exdata", package = "fars")) unique(data$STATE) # 56 par(mfrow = c(1,3)) for (i in 2013:2015) { fars_map_state(50, i) mtext(paste(i)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.