Tidy Tuesday - Interactive

PMAP 8551, Summer 2025

Author

Myah Vogt

Published

July 29, 2025

library(tidyverse)
library(tidytext)
library(maps)
library(lubridate)
library(plotly)

orcas <- readr::read_csv(
  "https://raw.githubusercontent.com/jadeynryan/orcas/refs/heads/master/data-raw/cwr_tidy.csv"
)

world_map <- map_data("world") %>%
  filter(region %in% c("Canada", "USA"))

orcas_mapping <- orcas %>%
  drop_na(begin_latitude, begin_longitude, date, begin_time) %>%
  mutate(
    year = year(date),
    formatted_date = format(as.Date(date), "%B %d, %Y"),
    formatted_time = format(strptime(begin_time, format = "%H:%M"), "%I:%M %p"),
    tooltip = paste(
      "Date: ", formatted_date, "<br>",
      "Time: ", formatted_time, "<br>",
      "Vessel: ", vessel, "<br>",
      "Observer(s): ", observers, "<br>",
      "Location: ", location
    )
  )

orca_interactive <- suppressWarnings(
  ggplot() +
    geom_polygon(
      data = world_map,
      aes(x = long, y = lat, group = group),
      fill = "gray95",
      color = "white"
    ) +
    geom_point(
      data = orcas_mapping,
      aes(
        x = begin_longitude,
        y = begin_latitude,
        color = factor(year),
        text = tooltip
      ),
      alpha = 0.7,
      size = 3
    ) +
    coord_fixed(
      xlim = c(-124, -122), 
      ylim = c(47, 50)
    ) +
    labs(
      title = "Interactive World Map of Orca Encounters",
      x = "Longitude",
      y = "Latitude",
      color = "Year"
    ) +
    theme_minimal()
)

ggplotly(orca_interactive, tooltip = "text")