if (FALSE) {
# View total crashes over time by data source
library(dplyr)
library(ggplot2)
annual_counts %>%
filter(involved == "any") %>%
ggplot(aes(x = year, y = n, fill = source)) +
geom_col(position = "dodge") +
labs(title = "Annual Crash Counts by Data Source",
x = "Year", y = "Number of Crashes")
# Compare risk factor trends in fatal crashes
annual_counts %>%
filter(source == "FARS",
involved %in% c("alcohol", "speeding", "distracted driver")) %>%
ggplot(aes(x = year, y = n, color = involved)) +
geom_line() +
labs(title = "Fatal Crash Trends by Risk Factor",
x = "Year", y = "Fatal Crashes")
}
Run the code above in your browser using DataLab