knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library('FARScoursera') library('dplyr') library('tidyr') library('readr') library('maps')
This package allows users to load, summarize, and visualize data on fatal motor vehicle accidents from the National Highway Traffic Safety Administration's Fatality Analysis Reporting System, which is a nationwide census tracking annual fatal injuries.
The package includes five functions to read the data, create a file, read the years, summarize the data by year, and to create the visualization at the state level.
The first option to loade data is with the fars_read() function. This creates a tibble.
df=fars_read()
This creates a standard file name for the data. This take the year as the only argument.
make_filename(2013)
This function will create a vector with a list of monthly data for the given years. This also utilizes the make_filename function and so creates files for each year automatically.
fars_read_years(c(2013:2015))
This creates a summary of all accidents by month for the selected years.
fars_summarize_years(c(2013:2015))
This plots the frequency of accidents in the selected state(s) for a selected year. Users can select multiple states but only a single year. The maps are drawn using the map() function from the "maps" package. The function takes two arguments. First is the state number, a numeric code for each state. The full list of codes can be found in the function's documentation. The second argument is the year.
fars_map_state(state.num, year)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.