fars_map_state: Make a map of accident data per state

Description Usage Arguments Details Value Note Examples

View source: R/fars_functions.R

Description

This function creates a map of accident data corresponding to the value of year argument. It then adds some points on the map based on the coordinates provided by the dataset.

Usage

1
fars_map_state(state.num, year)

Arguments

state.num

a numeric value of length 1

year

A four-digit number indicating the year in which the data collected.

Details

This function takes two numeric values as its arguments. It first calls make_filename and fars_read to create a character vector of file name corresponding to the argument year and then reads it into a tibble. If the date for that year does not exist in the working directory the function throws an error. It then coerced the numeric value for argument state.num into integer. After that it checks whether the required state.num exists in the column STATE in the dataset. If it does not exists the function throws an error mentioning that STATE number provided is invalid. Subsequently it calls to filter to create a subset of the data set based on state.num value. It then counts the number of rows of the subset and if it equals to zero a message appears on the console that no accidents to plot. The function turns the values which are greater than 900 on LONGITUD column of the data set and also values which are greater than 90 on LATITUDE column into NAs. It then call to map to make a map of subset data set by means of with. After that the function uses points to add some points on the map.

Value

A list with x and y range and names components.

Note

if you supply an invalid state.num to this function you will receive an error message "invalid STATE number". If there are no traffic fatalities you will receive a message "no accident to plot".

Examples

1
2
3
4
## Not run: 
fars_map_state(1, 2013)

## End(Not run)

AnoushiravanR/fars documentation built on Jan. 19, 2021, 5:16 p.m.