library(sf)
library(tidyverse)
library(ggmap)
library(rnoaa)
library(spData)
data(world)
data(us_states)
storm <- read_sf("08b_data/Basin.NA.ibtracs_all_points.v03r10.shp")
filteredStorm<-storm %>% filter(Season>="1950") %>%
dplyr::mutate_if(is.numeric, function(x) ifelse(x==-999.0,NA,x)) %>%
mutate(decade=floor(Season/10)*10)
region<-st_bbox(filteredStorm)
filteredWorld<-st_crop(world, region)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
ggplot() +
geom_sf(data=filteredWorld, inherit.aes= FALSE, fill="grey", colour="black")+
stat_bin2d(data=filteredStorm, aes(y=st_coordinates(filteredStorm)[,2], x=st_coordinates(filteredStorm)[,1]),bins=100) +
scale_fill_distiller(palette="YlOrRd", trans="log", direction=-1, breaks = c(1,10,100,1000))+ #sets color ramp
facet_wrap(~decade, nrow=2)+ #creates multiple plot panels for multiple decades
coord_sf(ylim=region[c(2,4)], xlim=region[c(1,3)])+ #crops the plot to region
labs(title="Hurricanes in the United States\nafter 1950")+
xlab("Latitude")+
ylab("Longitude")+
theme_classic()+
theme(legend.position="bottom")+
theme(plot.title = element_text(hjust=0.5))+
theme(axis.text.x = element_text(angle=90, hjust=1))
st_crs(filteredStorm) #gives us the crs value
## Coordinate Reference System:
## EPSG: 4326
## proj4string: "+proj=longlat +datum=WGS84 +no_defs"
states<-st_transform(us_states, crs=4326)
storm_states <- st_join(filteredStorm, states, join = st_intersects,left = F)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
table<-storm_states %>%
filter(Name!="UNNAMED") %>% #filter out storms with no name
group_by(NAME) %>%
distinct(Name) %>%
count(Name) %>%
count(NAME, sort=TRUE) %>%
st_set_geometry(NULL)
knitr::kable(table[1:5,])
| NAME | n |
|---|---|
| Florida | 76 |
| North Carolina | 50 |
| Georgia | 48 |
| Texas | 47 |
| South Carolina | 39 |