Last active
March 18, 2021 22:07
-
-
Save ianmcook/3d6ff19faab68face4fb5f9d5375f7ce to your computer and use it in GitHub Desktop.
Create map of North Carolina tornado alert polygons and home location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages(c("ggmap", "leaflet", "sp")) | |
devtools::install_github("ianmcook/weatherAlerts") | |
devtools::install_github("ianmcook/weatherAlertAreas") | |
# geocode home address | |
library(ggmap) | |
register_google("ENTER_GCP_GEOCODING_API_KEY_HERE") | |
home <- geocode("University of North Carolina at Chapel Hill") | |
# or specify coordinates of home | |
home <- data.frame(lon = -79.0469134, lat = 35.9049122) | |
library(weatherAlerts) | |
library(leaflet) | |
library(sp) | |
myLocation <- SpatialPoints( | |
coords = home, | |
proj4string = CRS("+proj=longlat +datum=WGS84") | |
) | |
alerts <- getAlerts(includeStates = c("NC")) # takes a few seconds | |
alerts <- alerts[alerts$event == "Tornado Warning",] | |
leaflet() %>% | |
addTiles() %>% | |
addPolygons(data = alerts, color = "black", fillColor = "magenta", weight = 1) %>% | |
addMarkers(lng = home$lon, lat = home$lat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment