2016-2017
# Load necessary libraries
library(ggplot2)
library(readxl)
library(sf)
library(tidyverse)
library(viridis)
# Set working directory
setwd("C:/Users/mvx13/OneDrive - Texas State University/Proposals/Proposal_Supp_Folder/2025_Proposals/Apr_Jul2025/0630_TCRP A-53/Proposal")
## 2016-2017
drought <- read_excel("StateBy1.xlsx")
head(drought)
## # A tibble: 6 × 7
## State `2016_2017` `2018_2019` `2020_2021` `2022_2023` State1 Code
## <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 Alabama 0 0 0 0 AL 1
## 2 Alaska 0 0 0 0 AK 2
## 3 Arizona 4 7 3 4 AZ 4
## 4 Arkansas 1 0 1 0 AR 5
## 5 California 28 31 18 13 CA 6
## 6 Colorado 4 6 6 10 CO 8
## [1] 51 7
hex_sf <- st_read("us_states_hexgrid.geojson")
## Reading layer `us_states_hexgrid' from data source
## `C:\Users\mvx13\OneDrive - Texas State University\Proposals\Proposal_Supp_Folder\2025_Proposals\Apr_Jul2025\0630_TCRP A-53\Proposal\us_states_hexgrid.geojson'
## using driver `GeoJSON'
## Simple feature collection with 51 features and 6 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -137.9747 ymin: 26.39343 xmax: -69.90286 ymax: 55.3132
## Geodetic CRS: WGS 84
# Transform to a projection (EPSG:3857) for uniform hexagon shape
hex_sf <- st_transform(hex_sf, 3857)
drought_df <- read_excel("StateBy1.xlsx")
# Rename columns for a clean join (state code and drought value)
drought_df1 <- drought_df %>%
rename(
iso3166_2 = State1, # match the state code column
drought_index = `2016_2017` # rename measure to a syntactic name
)
hex_drought_sf1 <- left_join(hex_sf, drought_df1, by = "iso3166_2")
ggplot(hex_drought_sf1) +
geom_sf(aes(fill = drought_index), color = "white", size = 0.2) + # hexagons colored by drought value
geom_sf_text(aes(label = iso3166_2), color = "white", size = 3) + # state abbreviation labels
scale_fill_viridis_c(name = "Transit Bus Fatal Crash (2016–2017)", option = "D", # viridis continuous scale (option "D" is standard viridis)
guide = guide_colorbar(title.position = "top", title.hjust = 0.5)) +
theme_void() +
theme(
legend.position = "bottom",
legend.title.align = 0.5
)

2018-2019
drought_df2 <- drought_df %>%
rename(
iso3166_2 = State1, # match the state code column
drought_index = `2018_2019` # rename measure to a syntactic name
)
hex_drought_sf2 <- left_join(hex_sf, drought_df2, by = "iso3166_2")
ggplot(hex_drought_sf2) +
geom_sf(aes(fill = drought_index), color = "white", size = 0.2) + # hexagons colored by drought value
geom_sf_text(aes(label = iso3166_2), color = "white", size = 3) + # state abbreviation labels
scale_fill_viridis_c(name = "Transit Bus Fatal Crash (2018–2019)", option = "D", # viridis continuous scale (option "D" is standard viridis)
guide = guide_colorbar(title.position = "top", title.hjust = 0.5)) +
theme_void() +
theme(
legend.position = "bottom",
legend.title.align = 0.5
)

2020-2021
drought_df3 <- drought_df %>%
rename(
iso3166_2 = State1, # match the state code column
drought_index = `2020_2021` # rename measure to a syntactic name
)
hex_drought_sf3 <- left_join(hex_sf, drought_df3, by = "iso3166_2")
ggplot(hex_drought_sf2) +
geom_sf(aes(fill = drought_index), color = "white", size = 0.2) + # hexagons colored by drought value
geom_sf_text(aes(label = iso3166_2), color = "white", size = 3) + # state abbreviation labels
scale_fill_viridis_c(name = "Transit Bus Fatal Crash (2020–2021)", option = "D", # viridis continuous scale (option "D" is standard viridis)
guide = guide_colorbar(title.position = "top", title.hjust = 0.5)) +
theme_void() +
theme(
legend.position = "bottom",
legend.title.align = 0.5
)

2022-2023
drought_df4 <- drought_df %>%
rename(
iso3166_2 = State1, # match the state code column
drought_index = `2022_2023` # rename measure to a syntactic name
)
hex_drought_sf4 <- left_join(hex_sf, drought_df4, by = "iso3166_2")
ggplot(hex_drought_sf2) +
geom_sf(aes(fill = drought_index), color = "white", size = 0.2) + # hexagons colored by drought value
geom_sf_text(aes(label = iso3166_2), color = "white", size = 3) + # state abbreviation labels
scale_fill_viridis_c(name = "Transit Bus Fatal Crash (2022–2023)", option = "D", # viridis continuous scale (option "D" is standard viridis)
guide = guide_colorbar(title.position = "top", title.hjust = 0.5)) +
theme_void() +
theme(
legend.position = "bottom",
legend.title.align = 0.5
)
