Caribou Locations

Maps with ggplot2, Calculating distance and speed with geosphere

Published

June 22, 2020

Notable topics: Maps with ggplot2, Calculating distance and speed with geosphere

Recorded on: 2020-06-22

Timestamps by: Eric Fletcher

View code

Screencast

Timestamps

summarizeacross
dplyr

Use summarize and across to calculate the proportion of NA values in the individuals dataset. Note, you do not need to use list().

ggplotborders
ggplot2

Use ggplot and borders from the ggplot2 package to create a map of Canada with deploy_on_longitude and deploy_on_latitude from the individuals dataset.

read_sf
sf

Import Canada province shapefile using the sf package. [Unsuccessful]

minmax
base

Use min and max from base r within summarize to find out the start and end dates for each caribou in the locations dataset.

samplegeom_path
baseggplot2

Use sample from base r to pick one single caribou at a time then use the subset with geom_path from ggplot2 to track the path a that caribou takes over time. color = factor(floor_date(timestamp, "quarter") is used to color the path according to what quarter the observation occured in.

as.Datefloor_date
baselubridate

Use as.Date from base r and floor_date from the lubridate package to convert timestamp variable into quarters then facet_wrap the previous plot by quarter.

difftimelag
base

Within mutate, use as.numeric(difftime(timestamp, lag(timestamp), unit = "hours")) from base r to figure out the gap in time between observations.

distHaversinecbind
geosphere

Use distHaversine from the geosphere package to calculate distance in km then convert it to speed in kph.

Summary of dataset.