edited dynamic_crash_map

This commit is contained in:
Ben Varick 2024-04-04 14:43:35 -05:00
parent 0209cf76f2
commit 2bb97b02b6
Signed by: ben
SSH Key Fingerprint: SHA256:758jG979jvr5HnQJl1AQ/NYTyzXRgnuoVM/yCR024sE
3 changed files with 5284 additions and 5264 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -5,6 +5,9 @@ library(leaflet)
library(RColorBrewer) library(RColorBrewer)
library(tidycensus) library(tidycensus)
library(htmltools) library(htmltools)
library(magick)
library(htmlwidgets)
## Load TOPS data ---- ## Load TOPS data ----
## To load TOPS data for the whole state for crashes involving bikes and pedestrians): ## To load TOPS data for the whole state for crashes involving bikes and pedestrians):
@ -77,6 +80,15 @@ TOPS_data <- TOPS_data %>%
TOPS_geom <- st_as_sf(TOPS_data %>% filter(!is.na(latitude)), coords = c("longitude", "latitude"), crs = 4326) TOPS_geom <- st_as_sf(TOPS_data %>% filter(!is.na(latitude)), coords = c("longitude", "latitude"), crs = 4326)
## load school locations ----
WI_schools <- st_read(dsn = "data/Schools/WI_schools.gpkg")
WI_schools <- WI_schools %>%
filter(is.double(LAT),
LAT > 0) %>%
select("SCHOOL", "DISTRICT", "SCHOOLTYPE", "LAT", "LON")
school_symbol <- image_read_svg(path = "other/school_FILL0_wght400_GRAD0_opsz24.svg")
## add county borders ---- ## add county borders ----
CountyBoundaries <- read_sf("data/WI_County_Boundaries_24K.geojson") CountyBoundaries <- read_sf("data/WI_County_Boundaries_24K.geojson")
@ -167,10 +179,18 @@ subtitle <- tags$div(
"</br>per direction of the WisDOT Bureau of Transportation Safety")) "</br>per direction of the WisDOT Bureau of Transportation Safety"))
) )
leaflet() %>% wisconsin_crash_map <- leaflet(options = leafletOptions(preferCanvas = TRUE)) %>%
# addControl(title, position = "topleft", className="map-title") %>% # addControl(title, position = "topleft", className="map-title") %>%
# addControl(subtitle, position = "bottomleft", className="map-subtitle") %>% # addControl(subtitle, position = "bottomleft", className="map-subtitle") %>%
addProviderTiles(providers$Stadia.AlidadeSmooth) %>% addProviderTiles(providers$Stadia.AlidadeSmooth) %>%
addMarkers(data = WI_schools,
lng=WI_schools$LON,
lat = WI_schools$LAT,
label = lapply(paste0("<b>", WI_schools$SCHOOL, " School</b></br>",
WI_schools$DISTRICT, " School District</br>",
WI_schools$SCHOOLTYPE), htmltools::HTML),
group = "Schools") %>%
groupOptions(group = "Schools", zoomLevels = 13:20) %>%
addCircleMarkers(data = Pedestrian_Crash_Data, addCircleMarkers(data = Pedestrian_Crash_Data,
lng=Pedestrian_Crash_Data$longitude, lng=Pedestrian_Crash_Data$longitude,
lat=Pedestrian_Crash_Data$latitude, lat=Pedestrian_Crash_Data$latitude,
@ -207,6 +227,6 @@ leaflet() %>%
# addLegendSize(position = "bottomright", color = "black", shape = "circle", values = County_Crash_Data$value.y, group = "Counties", title = "Population of County") %>% # addLegendSize(position = "bottomright", color = "black", shape = "circle", values = County_Crash_Data$value.y, group = "Counties", title = "Population of County") %>%
groupOptions(group ="Counties", zoomLevels = 1:9) groupOptions(group ="Counties", zoomLevels = 1:9)
saveWidget(wisconsin_crash_map, file = "figures/dynamic_crash_maps/wisconsin_crash_map.html")