knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Display the location of accidents for a specific year and state
First let set up the directory contianing he file
fars_dir = file.path("..","tests","data") list.files(fars_dir)
Loading dependancies
library(dplyr) library(readr) library(tidyr) library(magrittr) library(maps) library(knitr)
Loading the library
library(fars)
In the fars dataset numbers are used for states. We can find the correspondance with variable state.name
kable(data.frame(num=1:10,state=state.name[1:10]))
data2014 <- fars_read(make_filename(2014),fars_dir) data2014 %>% group_by(STATE) %>% summarize(n=n()) %>% mutate(state_name=state.name[STATE]) %>% arrange(desc(n))
Now we are using the fars_map_state
function to display the localisation of accident in California in 2014.
We may notice that California correspond to state 6 instead of 5.
library(ggplot2) fars_map_state(6,2013,fars_dir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.