North Atlantic Storms

Mapping Hurricanes Data I

Gaston Sanchez

Data storms

# A tibble: 19,537 × 13
   name   year month   day  hour   lat  long status      category  wind pressure
   <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <fct>          <dbl> <int>    <int>
 1 Amy    1975     6    27     0  27.5 -79   tropical d…       NA    25     1013
 2 Amy    1975     6    27     6  28.5 -79   tropical d…       NA    25     1013
 3 Amy    1975     6    27    12  29.5 -79   tropical d…       NA    25     1013
 4 Amy    1975     6    27    18  30.5 -79   tropical d…       NA    25     1013
 5 Amy    1975     6    28     0  31.5 -78.8 tropical d…       NA    25     1012
 6 Amy    1975     6    28     6  32.4 -78.7 tropical d…       NA    25     1012
 7 Amy    1975     6    28    12  33.3 -78   tropical d…       NA    25     1011
 8 Amy    1975     6    28    18  34   -77   tropical d…       NA    30     1006
 9 Amy    1975     6    29     0  34.4 -75.8 tropical s…       NA    35     1004
10 Amy    1975     6    29     6  34   -74.8 tropical s…       NA    40     1002
# ℹ 19,527 more rows
# ℹ 2 more variables: tropicalstorm_force_diameter <int>,
#   hurricane_force_diameter <int>

Plotting Storms Paths

Plot storms’ paths

View Plot Code
storms |>
  filter(year == 1975) |>
  ggplot(aes(x = long, y = lat, group = name)) +
  geom_point() +
  labs(title = "North Atlantic Storms (1975)")

Plot storms’ paths

View Plot Code
storms |>
  filter(year == 1975) |>
  ggplot(aes(x = long, y = lat, group = name)) +
  geom_point() +
  geom_path() + 
  labs(title = "North Atlantic Storms (1975)")

Plot storms’ paths

View Plot Code
storms |>
  filter(year == 1975) |>
  ggplot(aes(x = long, y = lat, group = name, color = name)) +
  geom_point(size = 1) +
  geom_path() + 
  labs(title = "North Atlantic Storms (1975)")

Plot storms’ paths

View Plot Code
storms |>
  filter(year == 1975) |>
  ggplot(aes(x = long, y = lat, group = name, color = name)) +
  geom_point(size = 1) +
  geom_path(arrow = arrow(length = unit(0.1, "inches"))) + 
  labs(title = "North Atlantic Storms (1975)")

Plot storms’ paths

View Plot Code
storms |>
  filter(year == 1975) |>
  ggplot(aes(x = long, y = lat, group = name, color = name)) +
  geom_point(size = 0.5, alpha = 0.5) +
  geom_path(arrow = arrow(length = unit(0.1, "inches"))) + 
  facet_wrap(~ month) +
  labs(title = "North Atlantic Storms (1975)") +
  theme_bw()

Maps

Wouldn’t this be nice?

What about something like this?

Maps in R

Our first approach involves packages:

  • "tidyverse" (data wrangling and exploration)

  • "sf" (simple features)

  • "rnaturalearth" (maps data)

Main Idea

Assuming that you have an "sf" (simple features) object (i.e. map data), you pass this to ggplot() and use the geom_sf() layer.

# (abstract code)
ggplot() + 
  geom_sf(data = map_object)


Or also (with more customizing options)

# (abstract code)
ggplot() + 
  geom_sf(data = map_object) +
  coord_sf(...)

Map Data from "rnaturalearth"

Examples:

  • ne_coastline(returnclass = "sf")

  • ne_countries(returnclass = "sf")

  • ne_countries(country = "mexico", returnclass = "sf")

Coast Line World Map

View Code
world_coast = ne_coastline(returnclass = "sf")

ggplot() + 
  geom_sf(data = world_coast)

Map of a given continent (e.g. North America)

View Code
map_north_america = ne_countries(
  continent = "north america", 
  returnclass = "sf")

ggplot() + 
  geom_sf(data = map_north_america) +
  theme(panel.background = element_blank())

Map of a given country (e.g. Mexico)

View Code
map_mexico1 = ne_countries(country = "mexico", returnclass = "sf")

ggplot() + 
  geom_sf(data = map_mexico1) +
  theme(panel.background = element_blank())

Map of a given country, with states (e.g. Mexico)

View Code
# (requires pkg "rnaturalearthhires")
# remotes::install_github("ropensci/rnaturalearthhires")
map_mexico2 = ne_states(country = "mexico", returnclass = "sf")

ggplot() + 
  geom_sf(data = map_mexico2) +
  theme(panel.background = element_blank())

Adding Data to a Map

# (abstract code)
ggplot() + 
  geom_sf(data = map_object) +
  geom_...(data = data_table, aes(...))


Or also:

# (abstract code)
ggplot() + 
  geom_sf(data = map_object) +
  geom_...(data = data_table, aes(...)) +
  geom_...(data = data_table, aes(...)) 

Adding Data to a Map

View Code
storms75 = storms |> filter(year == 1975)

ggplot() + 
  geom_sf(data = map_north_america) +
  geom_point(data = storms75, 
             aes(x = long, y = lat, group = name, color = name)) +
  theme(panel.background = element_blank()) +
  labs(title = "North Atlantic Storms (1975)")

Adding Data to a Map

View Code
storms75 = storms |> filter(year == 1975)

ggplot() + 
  geom_sf(data = map_north_america) +
  geom_point(data = storms75, size = 0.5,
             aes(x = long, y = lat, group = name, color = name)) +
  geom_path(data = storms75, 
             aes(x = long, y = lat, group = name, color = name)) +
  theme(panel.background = element_blank()) +
  labs(title = "North Atlantic Storms (1975)")

Adding Data to a Map

View Code
storms75 = storms |> filter(year == 1975)

ggplot() +
  geom_sf(data = world_countries) +
  coord_sf(xlim = c(-110, 0), ylim = c(5, 65)) +
  geom_path(data = storms75, 
          aes(x = long, y = lat, group = name, color = name)) +
  facet_wrap(~ year, nrow = 2) +
  theme(panel.background = element_blank(),
        axis.ticks = element_blank(), # hide tick marks
        axis.text = element_blank()) + # hide degree values of lat & lon
  labs(title = "North Atlantic Storms (1975)",
       x = "", 
       y = "")