knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

First, let's set the working directory to the directory with FARS data files.

require(fars.pack)
old_path <- getwd()
file_path <- system.file("extdata", package = "fars.pack")
dir(file_path)

There are 3 data files attached with this package. They consists of data from 2013 to 2015. Let's read this file with fars_read function.

setwd(file_path)
fars2015 <- fars_read(dir()[3])
head(fars2015)

The output tibble has 52 columns describing accidents. We can plot accidents on a map for a selected state. The function fars_map_state does that.

setwd(file_path)
# state number 1
fars_map_state(1, 2015)
# state number 10
fars_map_state(10, 2015)

Voila!



rafal-gl/package_coursera documentation built on May 20, 2019, 5:58 p.m.