Visualizing Polar Bear Migration Using R

James Jones
2 min readJan 3, 2024

--

Hey everyone! So, I worked on something pretty cool as part of my Data Science MSc and I wanted to share it with you all. I recently got my hands on a fascinating dataset from the United States Geological Survey (USGS) that tracks polar bear sightings, and I used R to create some awesome visualizations of their migration patterns.

Getting the Data

First things first, I snagged the dataset named "polarBear_serumUreaCreatinine_beaufortChukchi_rode.csv" from the USGS Alaska Science Center.

library(tidyverse)
library(gganimate)
library(gghighlight)
library(ggthemes)
library(gifski)
library(ggmap)

# Importing the data
polarBear_data <- read_csv("polarBear_serumUreaCreatinine_beaufortChukchi_rode.csv",
col_types = cols(`Capture Date` = col_date(format = "%d/%m/%Y"),
YearCaptured = col_integer()))

Exploring the Dataset

Let's take a quick peek into the dataset to see what we're dealing with:

View(polarBear_data)

It's got a bunch of columns like capture date, year captured, latitude, and longitude. I renamed a few columns to make things clearer:

pbears <- polarBear_data
names(pbears)[2] <- "CapDate"
names(pbears)[3] <- "CapYear"
names(pbears)[10] <- "lat1"
names(pbears)[11] <- "long1"

Visualizing the Migration

Static Map

I started off by creating a static map to show where these polar bear sightings happened between 1983 and 2017.

bearmap <- qmplot(long1, lat1, data = pbears, colour = I('red'), size = I(3), darken = .3, source = "stamen", maptype = "watercolor") +
labs(title = "Polar Bear Migration: Location of Polar Bear Sightings by Year. 1983-2017",
subtitle = "Year: {frame_time}",
caption = "Source: USGS Alaska Science Center")

bearmap

Animated Visualization

Then came the exciting part – making an animated visualization to showcase the migration over time:

graph_animation <- bearmap +
transition_time(CapYear) +
labs(subtitle = "Year: {frame_time}") +
shadow_wake(wake_length = 0.1)

animate(graph_animation, height = 500, width = 800, fps = 30, duration = 24,
end_pause = 60, res = 100)

This animation really brings the polar bear movement to life, giving us a dynamic look at how they migrate across different years.

So, using R’s visualization tools with geographic data, I gained some incredible insights into the migratory behavior of polar bears.

I hope you find this little adventure into polar bear migrations as exciting as I did!

gganimate ftw!

--

--

James Jones
James Jones

Written by James Jones

Health data scientist. Sharing personal data science/ machine learning projects! :)

No responses yet