Compare commits
2 Commits
ba4fb8b6c8
...
0209cf76f2
Author | SHA1 | Date | |
---|---|---|---|
0209cf76f2 | |||
4240921ada |
File diff suppressed because one or more lines are too long
@ -13,6 +13,7 @@ for (file in list.files(path = "data/TOPS/", pattern = "crash-data-download")) {
|
|||||||
message(paste("importing data from file: ", file))
|
message(paste("importing data from file: ", file))
|
||||||
year <- substr(file, 21, 24)
|
year <- substr(file, 21, 24)
|
||||||
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
||||||
|
csv_run["retreive_date"] <- file.info(file = paste0("data/TOPS/",file))$mtime
|
||||||
TOPS_data[[file]] <- csv_run
|
TOPS_data[[file]] <- csv_run
|
||||||
}
|
}
|
||||||
rm(csv_run, file, year)
|
rm(csv_run, file, year)
|
||||||
@ -28,6 +29,8 @@ TOPS_data <- TOPS_data %>%
|
|||||||
mutate(month = month(date, label = TRUE),
|
mutate(month = month(date, label = TRUE),
|
||||||
year = as.factor(year(date)))
|
year = as.factor(year(date)))
|
||||||
|
|
||||||
|
retrieve_date <- max(TOPS_data %>% filter(year %in% max(year(TOPS_data$date), na.rm = TRUE)) %>% pull(retreive_date))
|
||||||
|
|
||||||
# Injury Severy Index and Color -----
|
# Injury Severy Index and Color -----
|
||||||
injury_severity <- data.frame(InjSevName = c("No apparent injury", "Possible Injury", "Suspected Minor Injury","Suspected Serious Injury","Fatality"),
|
injury_severity <- data.frame(InjSevName = c("No apparent injury", "Possible Injury", "Suspected Minor Injury","Suspected Serious Injury","Fatality"),
|
||||||
code = c("O", "C", "B", "A", "K"),
|
code = c("O", "C", "B", "A", "K"),
|
||||||
@ -121,7 +124,10 @@ TOPS_data %>%
|
|||||||
x = "Year",
|
x = "Year",
|
||||||
y = "Total crashes per year per 100,000 residents",
|
y = "Total crashes per year per 100,000 residents",
|
||||||
color = "County",
|
color = "County",
|
||||||
caption = "data from UW TOPS lab\nretrieved 3/2024 per direction of the WisDOT Bureau of Transportation Safety") +
|
caption = paste0("crash data from UW TOPS lab - retrieved ",
|
||||||
|
strftime(retrieve_date, format = "%m/%Y"),
|
||||||
|
" per direction of the WisDOT Bureau of Transportation Safety",
|
||||||
|
"\nbasemap from StadiaMaps and OpenStreetMap Contributers")) +
|
||||||
theme(plot.caption = element_text(color = "grey"))
|
theme(plot.caption = element_text(color = "grey"))
|
||||||
|
|
||||||
ggsave(file = paste0("figures/crash_summaries/counties_year.pdf"),
|
ggsave(file = paste0("figures/crash_summaries/counties_year.pdf"),
|
||||||
|
@ -16,11 +16,11 @@ for (file in list.files(path = "data/TOPS/", pattern = "crash-data-download")) {
|
|||||||
message(paste("importing data from file: ", file))
|
message(paste("importing data from file: ", file))
|
||||||
year <- substr(file, 21, 24)
|
year <- substr(file, 21, 24)
|
||||||
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
||||||
|
csv_run["retreive_date"] <- file.info(file = paste0("data/TOPS/",file))$mtime
|
||||||
TOPS_data[[file]] <- csv_run
|
TOPS_data[[file]] <- csv_run
|
||||||
}
|
}
|
||||||
rm(csv_run, file, year)
|
rm(csv_run, file, year)
|
||||||
TOPS_data <- bind_rows(TOPS_data)
|
TOPS_data <- bind_rows(TOPS_data)
|
||||||
|
|
||||||
## clean up data ----
|
## clean up data ----
|
||||||
TOPS_data <- TOPS_data %>%
|
TOPS_data <- TOPS_data %>%
|
||||||
mutate(date = mdy(CRSHDATE),
|
mutate(date = mdy(CRSHDATE),
|
||||||
@ -31,6 +31,9 @@ TOPS_data <- TOPS_data %>%
|
|||||||
mutate(month = month(date, label = TRUE),
|
mutate(month = month(date, label = TRUE),
|
||||||
year = as.factor(year(date)))
|
year = as.factor(year(date)))
|
||||||
|
|
||||||
|
retrieve_date <- max(TOPS_data %>% filter(year %in% max(year(TOPS_data$date), na.rm = TRUE)) %>% pull(retreive_date))
|
||||||
|
|
||||||
|
|
||||||
# Injury Severy Index and Color -----
|
# Injury Severy Index and Color -----
|
||||||
injury_severity <- data.frame(InjSevName = c("No apparent injury", "Possible Injury", "Suspected Minor Injury","Suspected Serious Injury","Fatality"),
|
injury_severity <- data.frame(InjSevName = c("No apparent injury", "Possible Injury", "Suspected Minor Injury","Suspected Serious Injury","Fatality"),
|
||||||
code = c("O", "C", "B", "A", "K"),
|
code = c("O", "C", "B", "A", "K"),
|
||||||
@ -138,7 +141,10 @@ tag.map.title <- tags$style(HTML("
|
|||||||
"))
|
"))
|
||||||
|
|
||||||
title <- tags$div(
|
title <- tags$div(
|
||||||
tag.map.title, HTML("Pedestrians & Bicyclists hit by cars</br>2017-2023")
|
tag.map.title, HTML(paste0("Pedestrians & Bicyclists involved in a crash</br>",
|
||||||
|
min(year(TOPS_data$date), na.rm = TRUE),
|
||||||
|
" - ",
|
||||||
|
max(year(TOPS_data$date), na.rm = TRUE)))
|
||||||
)
|
)
|
||||||
|
|
||||||
tag.map.subtitle <- tags$style(HTML("
|
tag.map.subtitle <- tags$style(HTML("
|
||||||
@ -156,12 +162,14 @@ tag.map.subtitle <- tags$style(HTML("
|
|||||||
"))
|
"))
|
||||||
|
|
||||||
subtitle <- tags$div(
|
subtitle <- tags$div(
|
||||||
tag.map.subtitle, HTML("data from UW TOPS lab - retrieved 3/2024</br>per direction of the WisDOT Bureau of Transportation Safety")
|
tag.map.subtitle, HTML(paste0("data from UW TOPS lab - retrieved ",
|
||||||
|
strftime(retrieve_date, format = "%m/%Y"),
|
||||||
|
"</br>per direction of the WisDOT Bureau of Transportation Safety"))
|
||||||
)
|
)
|
||||||
|
|
||||||
leaflet() %>%
|
leaflet() %>%
|
||||||
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) %>%
|
||||||
addCircleMarkers(data = Pedestrian_Crash_Data,
|
addCircleMarkers(data = Pedestrian_Crash_Data,
|
||||||
lng=Pedestrian_Crash_Data$longitude,
|
lng=Pedestrian_Crash_Data$longitude,
|
||||||
@ -172,6 +180,9 @@ leaflet() %>%
|
|||||||
color = "black",
|
color = "black",
|
||||||
weight = 1,
|
weight = 1,
|
||||||
fillOpacity = 0.8,
|
fillOpacity = 0.8,
|
||||||
|
label = lapply(paste0("<b>", Pedestrian_Crash_Data$CrashDate, "</b></br>",
|
||||||
|
Pedestrian_Crash_Data$PedestrianInjurySeverity, "</br>",
|
||||||
|
"pedestrian age: ", Pedestrian_Crash_Data$PedestrianAge), htmltools::HTML),
|
||||||
group = "Crash Points") %>%
|
group = "Crash Points") %>%
|
||||||
addLegend(position = "bottomleft", labels = injury_severity$InjSevName, colors = injury_severity$color, group = "Crash Points", title = "Injury Severity") %>%
|
addLegend(position = "bottomleft", labels = injury_severity$InjSevName, colors = injury_severity$color, group = "Crash Points", title = "Injury Severity") %>%
|
||||||
groupOptions(group = "Crash Points", zoomLevels = 10:20) %>%
|
groupOptions(group = "Crash Points", zoomLevels = 10:20) %>%
|
||||||
@ -188,6 +199,9 @@ leaflet() %>%
|
|||||||
color = "black",
|
color = "black",
|
||||||
weight = 1,
|
weight = 1,
|
||||||
fillOpacity = 0.7,
|
fillOpacity = 0.7,
|
||||||
|
label = lapply(paste0("<b>", str_to_title(County_Crash_Data$County), " County</b></br>",
|
||||||
|
"mean pedestrian crashes/year: ", round(County_Crash_Data$MeanCrashes,0), "</br>",
|
||||||
|
"crashes/100,000 residents: ", round(County_Crash_Data$CrashesPerPopulation,0)), htmltools::HTML),
|
||||||
group = "Counties") %>%
|
group = "Counties") %>%
|
||||||
addLegend(position = "bottomleft", pal = county_pal, values = County_Crash_Data$CrashesPerPopulation, group = "Counties", title = "Mean Crashes/Year in County</br>(per 100,000 residents)") %>%
|
addLegend(position = "bottomleft", pal = county_pal, values = County_Crash_Data$CrashesPerPopulation, group = "Counties", title = "Mean Crashes/Year in County</br>(per 100,000 residents)") %>%
|
||||||
# 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") %>%
|
||||||
|
@ -20,10 +20,11 @@ library(parallel)
|
|||||||
## Load TOPS data ----
|
## Load TOPS data ----
|
||||||
## load TOPS data for the whole state (crashes involving bikes and pedestrians),
|
## load TOPS data for the whole state (crashes involving bikes and pedestrians),
|
||||||
TOPS_data <- as.list(NULL)
|
TOPS_data <- as.list(NULL)
|
||||||
for (file in list.files(path = "data/TOPS", pattern = "crash-data-download")) {
|
for (file in list.files(path = "data/TOPS/", pattern = "crash-data-download")) {
|
||||||
message(paste("importing data from file: ", file))
|
message(paste("importing data from file: ", file))
|
||||||
year <- substr(file, 21, 24)
|
year <- substr(file, 21, 24)
|
||||||
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
||||||
|
csv_run["retreive_date"] <- file.info(file = paste0("data/TOPS/",file))$mtime
|
||||||
TOPS_data[[file]] <- csv_run
|
TOPS_data[[file]] <- csv_run
|
||||||
}
|
}
|
||||||
rm(csv_run, file, year)
|
rm(csv_run, file, year)
|
||||||
@ -39,6 +40,8 @@ TOPS_data <- TOPS_data %>%
|
|||||||
mutate(month = month(date, label = TRUE),
|
mutate(month = month(date, label = TRUE),
|
||||||
year = as.factor(year(date)))
|
year = as.factor(year(date)))
|
||||||
|
|
||||||
|
retrieve_date <- max(TOPS_data %>% filter(year %in% max(year(TOPS_data$date), na.rm = TRUE)) %>% pull(retreive_date))
|
||||||
|
|
||||||
# county index
|
# county index
|
||||||
counties <- data.frame(name = c("Dane", "Milwaukee"),
|
counties <- data.frame(name = c("Dane", "Milwaukee"),
|
||||||
CNTYCODE = c(13, 40),
|
CNTYCODE = c(13, 40),
|
||||||
@ -143,7 +146,10 @@ for(county in county_focus) {
|
|||||||
" County"),
|
" County"),
|
||||||
x = "Year",
|
x = "Year",
|
||||||
y = "Number of crashes",
|
y = "Number of crashes",
|
||||||
caption = "data from UW TOPS Laboratory")
|
caption = paste0("crash data from UW TOPS lab - retrieved ",
|
||||||
|
strftime(retrieve_date, format = "%m/%Y"),
|
||||||
|
" per direction of the WisDOT Bureau of Transportation Safety",
|
||||||
|
"\nbasemap from StadiaMaps and OpenStreetMap Contributers"))
|
||||||
ggsave(file = paste0("figures/school_maps/Crash Maps/",
|
ggsave(file = paste0("figures/school_maps/Crash Maps/",
|
||||||
str_to_title(county),
|
str_to_title(county),
|
||||||
" County/_",
|
" County/_",
|
||||||
@ -292,7 +298,10 @@ for(district in district_focus) {
|
|||||||
min(year(TOPS_data$date), na.rm = TRUE),
|
min(year(TOPS_data$date), na.rm = TRUE),
|
||||||
" - ",
|
" - ",
|
||||||
max(year(TOPS_data$date), na.rm = TRUE)),
|
max(year(TOPS_data$date), na.rm = TRUE)),
|
||||||
caption = "crash data from UW TOPS lab - retrieved 3/2024 per direction of the WisDOT Bureau of Transportation Safety\nbasemap from StadiaMaps and OpenStreetMap Contributers",
|
caption = paste0("crash data from UW TOPS lab - retrieved ",
|
||||||
|
strftime(retrieve_date, format = "%m/%Y"),
|
||||||
|
" per direction of the WisDOT Bureau of Transportation Safety",
|
||||||
|
"\nbasemap from StadiaMaps and OpenStreetMap Contributers"),
|
||||||
x = NULL,
|
x = NULL,
|
||||||
y = NULL) +
|
y = NULL) +
|
||||||
theme(axis.text=element_blank(),
|
theme(axis.text=element_blank(),
|
||||||
|
@ -20,13 +20,14 @@ library(parallel)
|
|||||||
## Load TOPS data ----
|
## Load TOPS data ----
|
||||||
## load TOPS data for the whole state (crashes involving bikes and pedestrians),
|
## load TOPS data for the whole state (crashes involving bikes and pedestrians),
|
||||||
TOPS_data <- as.list(NULL)
|
TOPS_data <- as.list(NULL)
|
||||||
for (file in list.files(path = "data/TOPS", pattern = "crash-data-download")) {
|
for (file in list.files(path = "data/TOPS/", pattern = "crash-data-download")) {
|
||||||
message(paste("importing data from file: ", file))
|
message(paste("importing data from file: ", file))
|
||||||
year <- substr(file, 21, 24)
|
year <- substr(file, 21, 24)
|
||||||
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
||||||
|
csv_run["retreive_date"] <- file.info(file = paste0("data/TOPS/",file))$mtime
|
||||||
TOPS_data[[file]] <- csv_run
|
TOPS_data[[file]] <- csv_run
|
||||||
}
|
}
|
||||||
rm(csv_run)
|
rm(csv_run, file, year)
|
||||||
TOPS_data <- bind_rows(TOPS_data)
|
TOPS_data <- bind_rows(TOPS_data)
|
||||||
|
|
||||||
## clean up data
|
## clean up data
|
||||||
@ -39,6 +40,8 @@ TOPS_data <- TOPS_data %>%
|
|||||||
mutate(month = month(date, label = TRUE),
|
mutate(month = month(date, label = TRUE),
|
||||||
year = as.factor(year(date)))
|
year = as.factor(year(date)))
|
||||||
|
|
||||||
|
retrieve_date <- max(TOPS_data %>% filter(year %in% max(year(TOPS_data$date), na.rm = TRUE)) %>% pull(retreive_date))
|
||||||
|
|
||||||
# county index
|
# county index
|
||||||
counties <- data.frame(name = c("Dane", "Milwaukee"),
|
counties <- data.frame(name = c("Dane", "Milwaukee"),
|
||||||
CNTYCODE = c(13, 40),
|
CNTYCODE = c(13, 40),
|
||||||
@ -147,7 +150,10 @@ for(county in county_focus) {
|
|||||||
labs(title = paste0("Pedestrians/bicyclists under 18 years old hit by cars in ",
|
labs(title = paste0("Pedestrians/bicyclists under 18 years old hit by cars in ",
|
||||||
str_to_title(county),
|
str_to_title(county),
|
||||||
" County"),
|
" County"),
|
||||||
caption = "crash data from UW TOPS lab - retrieved 3/2024 per direction of the WisDOT Bureau of Transportation Safety",
|
caption = paste0("crash data from UW TOPS lab - retrieved ",
|
||||||
|
strftime(retrieve_date, format = "%m/%Y"),
|
||||||
|
" per direction of the WisDOT Bureau of Transportation Safety",
|
||||||
|
"\nbasemap from StadiaMaps and OpenStreetMap Contributers"),
|
||||||
x = "Year",
|
x = "Year",
|
||||||
y = "Number of crashes")
|
y = "Number of crashes")
|
||||||
ggsave(file = paste0("~/temp/wi_crashes/figures/crash_maps/Crash Maps/",
|
ggsave(file = paste0("~/temp/wi_crashes/figures/crash_maps/Crash Maps/",
|
||||||
@ -295,7 +301,10 @@ generate_school_maps <- function(district) {
|
|||||||
min(year(TOPS_data$date), na.rm = TRUE),
|
min(year(TOPS_data$date), na.rm = TRUE),
|
||||||
" - ",
|
" - ",
|
||||||
max(year(TOPS_data$date), na.rm = TRUE)),
|
max(year(TOPS_data$date), na.rm = TRUE)),
|
||||||
caption = "crash data from UW TOPS lab - retrieved 3/2024 per direction of the WisDOT Bureau of Transportation Safety\nbasemap from StadiaMaps and OpenStreetMap Contributers",
|
caption = paste0("crash data from UW TOPS lab - retrieved ",
|
||||||
|
strftime(retrieve_date, format = "%m/%Y"),
|
||||||
|
" per direction of the WisDOT Bureau of Transportation Safety",
|
||||||
|
"\nbasemap from StadiaMaps and OpenStreetMap Contributers"),
|
||||||
x = NULL,
|
x = NULL,
|
||||||
y = NULL) +
|
y = NULL) +
|
||||||
theme(axis.text=element_blank(),
|
theme(axis.text=element_blank(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user