path <- "/Users/yuhe/Downloads/gdswr_data/Chapter5"
okcounty <- st_read(paste0(path,"/ok_counties.shp"), quiet = TRUE)
tpoint <- st_read(paste0(path,"/ok_tornado_point.shp"), quiet = TRUE)
tpath <- st_read(paste0(path,"/ok_tornado_path.shp"), quiet = TRUE)
ggplot(data = okcounty) +
geom_sf(fill = NA) +
geom_sf(aes(fill = GEOID)) +
theme(legend.position = "none")
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)
ggplot() +
geom_sf(data = okcounty, fill = NA) +
geom_sf(data = tpoint_16_21, aes(color = as.factor(yr))) +
theme_bw()
tpoint_00_21 <- tpoint %>%
filter(yr >= 2000 & yr <= 2021) %>%
select(om, yr, date, inj)
countypnt <- st_join(tpoint_00_21, okcounty)
countypnt <- st_drop_geometry(countypnt)
countysum <- countypnt %>%
group_by(GEOID) %>%
summarize(tcnt = n())
countymap <- okcounty %>%
left_join(countysum, by = "GEOID") %>%
replace(is.na(.), 0) %>%
mutate(area = st_area(okcounty),
tdens = 10^6 * 10^3 * tcnt / area) %>%
drop_units()
ggplot(data = countymap) +
geom_sf(aes(fill = tdens)) +
scale_fill_distiller(name = expression("Tornadoes/1000 km"^2),
palette = "YlOrRd",
breaks = pretty_breaks(),
direction = 1) +
theme_void() +
theme(legend.position = "bottom")
countysum2 <- countypnt %>%
group_by(GEOID) %>%
summarize(injuries = mean(inj))
countymap2 <- okcounty %>%
left_join(countysum2, by = "GEOID")
ggplot(data = countymap2) +
geom_sf(aes(fill = injuries)) +
scale_fill_distiller(name = expression("Average injuries per Year"),
palette = "YlOrBr",
breaks = pretty_breaks(),
direction = 1) +
theme_void() +
theme(legend.position = "bottom")
countymap2 <- countymap2 %>%
mutate(injuries_c = cut(injuries,
breaks = c(0,2,4,6,8,10,Inf),
include.lowest = T))
ggplot(data = countymap2) +
geom_sf(aes(fill = injuries)) +
scale_fill_distiller(name = expression("Average injuries per Year"),
palette = "YlOrBr",
breaks = pretty_breaks(),
direction = 1) +
theme_void() +
theme(legend.position = "bottom")
p1 <- ggplot() +
geom_sf(data = okcounty, fill = NA) +
geom_sf(data = tpath_16_21, aes(color = as.factor(yr)))
p2 <- ggplot() +
geom_sf(data = okcounty, fill = NA) +
geom_sf(data = tpoint_16_21, aes(color = as.factor(yr)))
plot_grid(p1, p2, labels = c("Tornado Path by Year", "Tornado Touchdown by Year"))