Skip to content

Instantly share code, notes, and snippets.

@vgXhc
Created September 2, 2024 23:34
Show Gist options
  • Save vgXhc/d524332a0b1c6eecadd0ba4310361285 to your computer and use it in GitHub Desktop.
Save vgXhc/d524332a0b1c6eecadd0ba4310361285 to your computer and use it in GitHub Desktop.
Creates a graph of bike crashes by month, with September highlighted
library(pins)
library(sf)
library(tidyverse)
library(lubridate)
library(jsonlite)
board <- board_s3("vzpins",
region = "us-east-1",
access_key = "",
secret_access_key = "")
crashes_all_dane <- pin_read(board = board, name = "crashes_all_dane")
crashes_all_dane |>
st_drop_geometry() |>
filter(bikeflag == "Y" & year < 2024) |>
group_by(month = month(date, label = T, abbr = T)) |>
summarise(n = n()) |>
ggplot(aes(month, n)) +
geom_col() +
xlab(element_blank()) +
ylab("Number of reported crashes") +
labs(title = "Drive carefully: September has the highest number of bike crashes in the year",
subtitle = "Police-reported motor vehicle crashes involving a bike rider in the City of Madison, 2017-2023",
caption = "Data: Community Maps/TOPS Lab\nVisualization: Harald Kliems") +
gghighlight::gghighlight(month == "Sep") +
hrbrthemes::theme_ipsum() +
theme(panel.grid.major.x = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment