Skip to content

Tracking of hurricanes and typhoons

Thomas Lin Pedersen edited this page Dec 10, 2018 · 2 revisions

Submitted by Wenlong Liu

Recently I generated an animated map to track the path of Typhoon Doksuri happened in Asia. I hope this post can be served as a wiki example to help generate animated maps.

Import packages and data

require(gganimate)
require(tidyverse)
require(lubridate)
require(ggmap)
require(maps)
require(mapdata)

# import data hosted in my github rep. 
typhoon_data <- read.csv("https://raw.github.com/wenlong-liu/typhoon_animation/master/Data/typhoon_doksuri.csv")

# data cleaning.
tracks <-  typhoon_data %>% 
  # reforamt date time using lubridate package. 
  mutate(time = mdy_hm(time)) %>% 
  # rename columns.
  rename(long = lng) 

Drawing an animated tracking map.

The author drew an animated tracking map using gganimate. In the subtitle of the plot, a real-time clock was added to show the timeline of the tracking path.

# draw a base box for maps.
tracks_box <- make_bbox(lon = tracks$long, lat = tracks$lat, f = 0.5)
sq_map <- get_map(location = tracks_box, maptype = "satellite", source = "google", zoom = 5)

# plot map.
ggmap(sq_map) + 
  theme(text = element_text(size = 17))+
  geom_point(data = tracks, mapping = aes(x = long, y = lat, color = pressure)) +
  geom_line(data = tracks, mapping = aes(x = long, y = lat, color = pressure), size = 2) +
  scale_color_continuous(name = "Pressure(hPa)",low = "yellow", high = "red")+
  labs(title = "Tracking of Typhoon Doksuri happened in 2017",
      subtitle = "Time:{frame_time}",
      x = "Long", y = "Lat", 
      caption = "Data Source: jswater.jiangsu.gov.cn")+
  transition_reveal(time)+
  NULL

doksuri_tracking

Source:

The example was adapted from this blog post