added vehicle types

This commit is contained in:
Ben Varick 2025-09-25 12:12:52 -07:00
parent 2c64a02ad5
commit d830526659
Signed by: ben
SSH key fingerprint: SHA256:jWnpFDAcacYM5aPFpYRqlsamlDyKNpSj3jj+k4ojtUo
2 changed files with 66 additions and 3 deletions

View file

@ -707,8 +707,8 @@ TOPS_data <- TOPS_data %>% mutate(trickortreat = ifelse(date %in% trickortreatda
```
## explore graphs
```{r exploreGraphs, eval = TRUE, echo = TRUE, results = "show", warning = FALSE, error = TRUE, message = FALSE}
## Halloween
```{r exploreHalloween, eval = TRUE, echo = TRUE, results = "show", warning = FALSE, error = TRUE, message = FALSE}
ggplot(data = TOPS_data_filtered %>%
# filter(ped_inj %in% c("K", "A", "B")) %>%
# filter(ped_age <=18) %>%
@ -772,4 +772,43 @@ ggsave(filename = paste0("figures/MilWALKee_Walks/", "halloween_wday.png"),
units = "in",
create.dir = TRUE)
```
## Trucks
```{r exploreTrucks, eval = TRUE, echo = TRUE, results = "show", warning = FALSE, error = TRUE, message = FALSE}
TOPS_data_filtered %>%
filter(ped_age < 18) %>%
filter(nonvuln_vehicletype != "Other") %>%
filter(vulnerable_role == "Pedestrian") %>%
group_by(ped_inj_name, nonvuln_vehicletype) %>%
summarise(total = n()) %>%
group_by(nonvuln_vehicletype) %>%
mutate(percent = total/sum(total),
cumpercent = cumsum(total)/sum(total)) %>%
ggplot(aes(x = nonvuln_vehicletype,
y = percent,
fill = ped_inj_name)) +
geom_col() +
geom_label(aes(label = paste0(round(percent * 100, 1), "%"),
fill = ped_inj_name),
position = position_stack(vjust = 0.5)) +
scale_fill_manual(values = setNames(injury_severity$color, injury_severity$InjSevName), name = "Injury severity") +
scale_y_continuous(labels = scales::percent) +
labs(title = paste0("Car crashes involving pedestrians - Children"),
subtitle = paste0(str_to_title(focus_county), " County | ", year_min, " - ", year_max),
x = NULL,
y = "Percent of crashes",
caption = paste0("crash data from UW TOPS lab - retrieved ",
strftime(retrieve_date, format = "%m/%Y"),
"\nper direction of the WisDOT Bureau of Transportation Safety")) +
theme(plot.caption = element_text(color = "grey"))
ggsave(filename = paste0("figures/MilWALKee_Walks/", "trucks_injsev.png"),
device = png,
height = 8.5,
width = 11,
units = "in",
create.dir = TRUE)
```

View file

@ -106,7 +106,7 @@ TOPS_data <- TOPS_data %>% mutate(vulnerable_role = ifelse(ROLE1 %in% bike_roles
NA)))
```
## Add race names to TOPS data
## Add race data to TOPS data
```{r TOPSrace, eval = TRUE, echo = TRUE, results = "show", warning = FALSE, error = TRUE, message = FALSE}
race <- data.frame(race_name = c("Asian", "Black", "Indian","Hispanic","White"),
code = c("A", "B", "I", "H", "W"))
@ -120,6 +120,30 @@ TOPS_data <- TOPS_data %>% mutate(vulnerable_race = ifelse(ROLE1 %in% vuln_roles
NA)))
```
## Add vehicle type
```{r TOPSvehicletype, eval = TRUE, echo = TRUE, results = "show", warning = FALSE, error = TRUE, message = FALSE}
trucksuv <- c("SUV", "UT TRK")
car <- c("CAR")
# definitions: https://transportal.cee.wisc.edu/documents/applications/crash-data/advanced/TOPS%20DT4000%20Crash%20Data%20Elements%20and%20Attributes_20250604.pdf
TOPS_data <- TOPS_data %>%
mutate(nonvuln_vehicletype = ifelse(ROLE1 %in% vuln_roles,
ifelse(VEHTYPE2 %in% trucksuv,
"Truck/SUV",
ifelse(VEHTYPE2 %in% car,
"Car",
"Other")
),
ifelse(VEHTYPE1 %in% trucksuv,
"Truck/SUV",
ifelse(VEHTYPE1 %in% car,
"Car",
"Other")
)
)
)
```
## Save resulting data table as an Rda file for use in other documents
```{r savecleaneddata, eval = TRUE, echo = TRUE, results = "show", warning = FALSE, error = TRUE, message = FALSE}
save(TOPS_data, file = "data/TOPS/TOPS_data.Rda")