knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(CourseraBuildingRPckg) library(dplyr) library(maps)
CourseraBuildingRPckg is a peer reviewed project to practice R package Building
This packages provides functions to process and plot data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System.
Process data with fars_summarize_years()
Visualize data with fars_map_state()
Those functions require that current working directory contains FARS data from the given year named like accident_[year].csv.bz2
The packages has 3 files relating the FARS data from 2013 to 2015.
They are accessible under the folder accessible by running the following line.
system.file("extdata", package = "CourseraBuildingRPckg")
Those files can also be used by setting current directory as following right before calling the function (in the same chunk):
setwd(system.file("extdata", package = "CourseraBuildingRPckg"))
Let's process the accidents data of 2013 by summarizing them by month in year in a tibble using the fars_summarize_years()
function.
setwd(system.file("extdata", package = "CourseraBuildingRPckg")) #Needed if you want to use data from the package, otherwise function will look for files in the directory the function is run. #getwd() fars_2013 <- fars_summarize_years(2013) fars_2013
Nota Bene fars_summarize_years()
can also create a summary report for multiple years.
setwd(system.file("extdata", package = "CourseraBuildingRPckg")) fars_2013_2014 <- fars_summarize_years(c(2013, 2014)) fars_2013_2014
The fars_map_state
function will plot all accidents locations for a given year and federal state on a US federal state map.
setwd(system.file("extdata", package = "CourseraBuildingRPckg")) fars_map_state(26, 2014)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.