Skip to content

Instantly share code, notes, and snippets.

@FlicAnderson
Forked from hrbrmstr/track_danny.R
Last active August 29, 2015 14:27
Show Gist options
  • Save FlicAnderson/5f6e1a86608eb39c6972 to your computer and use it in GitHub Desktop.
Save FlicAnderson/5f6e1a86608eb39c6972 to your computer and use it in GitHub Desktop.
Track Hurricane Danny (or any other Unisys-data-available-tropical storm)
library(leaflet)
library(stringi)
library(htmltools)
library(RColorBrewer)
# get tracks
danny <- readLines("http://weather.unisys.com/hurricane/atlantic/2015/DANNY/track.dat")
# extract data
danny_dat <- read.table(textConnection(gsub("TROPICAL ", "TROPICAL_", danny[3:length(danny)])),
header=TRUE, stringsAsFactors=FALSE)
# make storm type names prettier
danny_dat$STAT <- stri_trans_totitle(gsub("_", " ", danny_dat$STAT))
# make column names prettier
colnames(danny_dat) <- c("advisory", "lat", "lon", "time", "wind_speed", "pressure", "status")
# assign colors
danny_dat$color <- as.character(factor(danny_dat$status,
levels=c("Tropical Depression", "Tropical Storm",
"Hurricane-1", "Hurricane-2", "Hurricane-3",
"Hurricane-4", "Hurricane-5"),
labels=rev(brewer.pal(7, "YlOrBr"))))
# draw the map
leaflet() %>%
addTiles() %>%
addPolylines(data=danny_dat[danny_dat$advisory<=9,], ~lon, ~lat, color=~color) %>%
addCircles(data=danny_dat[danny_dat$advisory>9,], ~lon, ~lat, color=~color, fill=~color, radius=25000,
popup=~sprintf("<b>Advisory forecast for +%dh (%s)</b><hr noshade size='1'/>
Position: %3.2f, %3.2f<br/>
Expected strength: <span style='color:%s'><strong>%s</strong></span><br/>
Forecast wind: %s (knots)<br/>Forecast pressure: %s",
htmlEscape(advisory), htmlEscape(time), htmlEscape(lon),
htmlEscape(lat), htmlEscape(color), htmlEscape(status),
htmlEscape(wind_speed), htmlEscape(pressure))) %>% html_print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment