Description Usage Arguments Details Value Note Examples
This function can be used to create a map of fatalities in a US State during a year as reported in the FARS database.
1 | fars_map_state(state.num, year)
|
state.num |
State number as coded in the |
year |
A scalar year. |
This function takes the state number and a year as inputs and
performs the following operations on them:
- calls the supporting function, make_filename()
, with
the year to generate a list of MONTH and year,
- calls the supporting function, fars_read()
, to read the
FARS data file with the generated filename,
- If the state number (provided as the input parameter) is NOT
found in the FARS data file read: stops the execution with a
message, "invalid STATE number: xxx".
- For a valid STATE number:
- calls the filter()
function from the dplyr
package to extract the data for the STATE number provided,
- If no data exists for the state number: prints a message,
"no accidents to plot" and returns NULL.
- Otherwise:
- sets the invalid data for longitude (values greater than 900)
and latitude(values greater than 90), if any, to NA, and
- with the cleaned, mappable data:
- calls the map()
function of the maps
package to
draw the map of the State, and
- calls the points()
function of the base graphics
package to draw points on the longitude, latitude coordinates
as documented in the FARS dataset for that year in that State.
This function draws a map of the State and places points on it – one point for EACH fatality that occurred in that State.
Following functions need to be imported:
dplyr
package: filter()
.
maps
package: map()
.
graphics
base package: points()
.
Some validaiton is performed in this function as described in the
"Details" section.
1 2 3 4 | ## Not run:
fars_map_state(1, 2014) # Fatalities map for State #1 during 2014
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.