-
-
Save jonathanlxy/93e7c811d602a64e78dd1c7b40452a3b to your computer and use it in GitHub Desktop.
Vision Zero Visualization Blog Post Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Accident count percentage change | |
accident_p_vec <- c(0, tail(accident_n_dt$N, nrow(accident_n_dt) - 1) / | |
head(accident_n_dt$N, nrow(accident_n_dt) - 1) - 1) | |
# Number of registered vehicles in NYC | |
# https://dmv.ny.gov/about-dmv/statistical-summaries | |
reg_nyc <- data.table(Year = seq(2012, 2015), | |
Reg_num = c(1978392, | |
2016158, | |
2057433, | |
2107321)) | |
# Registration percentage change | |
reg_p_vec <- c(0, tail(reg_nyc$Reg_num, nrow(reg_nyc)-1) / | |
head(reg_nyc$Reg_num, nrow(reg_nyc)-1) - 1) | |
temp <- data.frame(PERIOD = rep(sort(unique(work_dt$PERIOD)), 2), | |
TYPE = rep(c('Motor Vehicle Collision', | |
'Vehicle Registration in NYC'), each = 4), | |
VALUE = c(accident_p_vec, reg_p_vec)) | |
# Visualize changes | |
ggplot(data = temp, | |
aes(x = PERIOD, y = VALUE, color = TYPE, group = TYPE)) + | |
geom_point(size = 3) + | |
geom_line(size = 2, alpha = .8) + | |
scale_y_continuous(labels = scales::percent) + | |
theme(legend.position = 'none') + | |
labs(title = 'Yearly Growth Rate', y = '% Growth Since Last Year') + | |
facet_wrap( ~ TYPE, nrow = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment