knitr::opts_chunk$set(echo = TRUE, 
                      fig.width = 10, 
                      fig.asp = 1, 
                      fig.align = "center")
library(dplyr)
library(ggplot2)
library(rrricanes)
library(sp)
key <- "AL092008"
adv <- 42
wndprb <- wndprb |> filter(StormKey == key, Adv <= adv)

GIS Advisory Forecast Track, Cone of Uncertainty, and Watches/Warnings

gis_adv <- gis_advisory(key = key, advisory = adv) |> gis_download()

Get bounding box of the forecast polygon.

bbox <- bbox(gis_adv$al092008.042_5day_pgn)
bbox

Build a Tracking Chart

Generate a base plot of the Atlantic ocean.

bp <- al_tracking_chart(color = "black", fill = "white", size = 0.1, res = 50)
bp

I like to add a little cushion for the map inset and forecast cone data.

lat_min <- bbox[2,1] - 5
lat_max <- bbox[2,2] + 5
lon_min <- bbox[1,1] - 10
lon_max <- bbox[1,2] + 10

Build a thin tracking map for the inset.

bp_inset <- ggplotGrob(bp +
            geom_rect(mapping = aes(xmin = lon_min, xmax = lon_max,
       ymin = lat_min, ymax = lat_max),
            color = "red", alpha = 0) +
                           theme_bw() +
                           theme(axis.title = element_blank(),
                                 axis.ticks = element_blank(),
                                 axis.text.x = element_blank(),
                                 axis.text.y = element_blank(),
                                 plot.margin = margin(0, 0, 0, 0, "pt")))

Modify original bp zoomed in on our area of interest.

bp <- bp +
    coord_equal(xlim = c(lon_min, lon_max),
                ylim = c(lat_min, lat_max)) +
    scale_x_continuous(expand = c(0, 0)) +
    scale_y_continuous(expand = c(0, 0)) +
    labs(x = "Lon",
         y = "Lat",
         caption = sprintf("rrricanes %s", packageVersion("rrricanes")))
bp

Combine bp and bp_inset to finalize initial base plot. bp will be a base plot without the inset. bpi will have the inset.

bpi <- bp + annotation_custom(grob = bp_inset, xmin = lon_max - 5,
                              xmax = lon_max - 1, ymin = -Inf,
                              ymax = lat_min + 5)
bpi

The wndprb will not have coordinates for cities. An option is al_prblty_stations. However, please note this function may become deprecated.

wndprb <- 
    wndprb |> 
    left_join(al_prblty_stations(), by = "Location") |> 
    mutate_at(.vars = c("Lat", "Lon"), .funs = as.numeric)

Check wndprb for NA values in Lat, Lon.

any(is.na(wndprb$Lat), is.na(wndprb$Lon))
wndprb_adv42 <- filter(wndprb, Adv == adv, Wind >= 64)

bpi +
    geom_point(
        data = wndprb_adv42, 
        aes(
            x = Lon,
            y = Lat, 
            color = Wind120Cum,
            size = Wind120Cum
        )
    ) + 
    scale_color_gradientn(colors = terrain.colors(10)) + 
    guides(size = FALSE) + 
    theme(
        legend.position = "bottom", 
        legend.box = "vertical"
    ) + 
    labs(title = "Total Probability of Wind >= 64kts within 120 Hours")


timtrice/Hurricanes documentation built on Oct. 10, 2023, 8:15 p.m.