library(sf)
library(sp)
library(here)
library(tidyverse)
library(units)
library(scales)
library(RColorBrewer)
library(cowplot)
okcounty <- st_read(here("data", "ok_counties.shp"), quiet = TRUE)
tpoint <- st_read(here("data", "ok_tornado_point.shp"), quiet = TRUE)
tpath <- st_read(here("data", "ok_tornado_path.shp"), quiet = TRUE)
tpoint_16_21 <- tpoint %>%
filter(yr >= 2016 & yr <= 2021) %>%
select(om, yr, date)
tpath_16_21 <- tpath %>%
filter(yr >= 2016 & yr <= 2021) %>%
select(om, yr, date)
tor_paths <- ggplot() +
geom_sf(data = tpath_16_21,
aes(color = as.factor(yr))) + # set year as factor instead of int
geom_sf(data = okcounty, fill = NA) +
scale_color_discrete(name = "Year") +
coord_sf(datum = NA) +
theme_void()
tor_points <- ggplot() +
geom_sf(data = tpoint_16_21,
aes(color = as.factor(yr))) +
geom_sf(data = okcounty, fill = NA) +
scale_color_discrete(name = "Year") +
coord_sf(datum = NA) +
theme_void()
plot_grid(tor_paths, tor_points,
labels = c("A) Tornado paths",
"B) Tornado touchdowns",
label_size = 12),
ncol = 1,
hjust = 0,
label_x = 0,
align = "hv")
tpoint_16_21 <- tpoint_16_21 %>%
st_join(okcounty) %>%
st_drop_geometry()
okcounty$AREA_KM2 <- st_area(okcounty) / 10^6
tdens <- tpoint_16_21 %>%
group_by(yr, GEOID) %>%
summarise(tcnt = n()) %>%
ungroup()
okcounty <- left_join(okcounty, tdens, by = "GEOID")
okcounty$tdens <- okcounty$tcnt / okcounty$AREA_KM2 * 1000
ggplot() +
geom_sf(data = na.omit(okcounty), aes(fill = tcnt)) +
scale_fill_gradient(name = "Tornado Count", low = "yellow", high = "red") +
facet_wrap(~yr, nrow = 2) +
theme_void() +
labs(title = "Tornado Count by County for Each Year (2016-2021)")
class_3 <- ggplot() +
geom_sf(data = na.omit(okcounty), aes(fill = tcnt)) +
scale_fill_gradient(name = "Legend", breaks = quantile(okcounty$tcnt, probs = c(0, 0.33, 0.66, 1), na.rm = TRUE), labels = c("0%", "33%", "66%", "100%")) +
theme_void()
class_4 <- ggplot() +
geom_sf(data = na.omit(okcounty), aes(fill = tcnt)) +
scale_fill_gradient(name = "Legend", breaks = quantile(okcounty$tcnt, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE), labels = c("0%", "25%", "50%", "75%","100%")) +
theme_void()
class_5 <- ggplot() +
geom_sf(data = na.omit(okcounty), aes(fill = tcnt)) +
scale_fill_gradient(name = "Legend", breaks = quantile(okcounty$tcnt, probs = c(0, 0.2, 0.4, 0.6, 0.8, 1), na.rm = TRUE), labels = c("0%", "20%", "40%", "60%","80%", "100%")) +
theme_void()
class_6 <- ggplot() +
geom_sf(data = na.omit(okcounty), aes(fill = tcnt)) +
scale_fill_gradient(name = "Legend", breaks = quantile(okcounty$tcnt, probs = c(0, 0.16, 0.33, 0.50, 0.66, 0.83, 1), na.rm = TRUE), labels = c("0%", "16%", "33%", "50%","66%", "83%", "100%")) +
theme_void()
plot_grid(class_3, class_4, class_5, class_6,
labels = c("A) 3 classes",
"B) 4 classes",
"C) 5 classes",
"D) 6 classes",
label_size = 12),
ncol = 2,
hjust = 0,
label_x = 0,
align = "hv")