This is the first of several posts based on a workshop I developed as an introduction to analyzing telemetry data in R. I will use a simulated data set to demonstrate basic movement analyses in R for telemetry data.

Update 2020-04-02 I have updated the ggmap section to account for Google’s change in API. The tutorial now uses Stamen tiles, but I included code for downloading Google tiles and a link on how to register for a key.


  1. Simulate data and format for spatial analyses using the sp package
  2. Create a map of telemetry points (and paths) using the ggmap package

1. Load data and format for spatial analyses

Let’s simulate some simple data for three animals as an example.

## Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
##   ..@ data       :'data.frame':  300 obs. of  1 variable:
##   .. ..$ id: num [1:300] 1 1 1 1 1 1 1 1 1 1 ...
##   ..@ coords.nrs : int [1:2] 2 3
##   ..@ coords     : num [1:300, 1:2] 284973 284962 285019 284983 284942 ...
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:300] "1" "2" "3" "4" ...
##   .. .. ..$ : chr [1:2] "x" "y"
##   ..@ bbox       : num [1:2, 1:2] 284882 5081287 287648 5082941
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "x" "y"
##   .. .. ..$ : chr [1:2] "min" "max"
##   ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
##   .. .. ..@ projargs: chr NA

Notice the slot for “proj4string” of class ‘CRS’. This refers to the coordinate reference system data and describes how the x and y coordinates are mapped on the globe. Our example data was collected in UTM in zone 18 in the WGS84 datum. Let’s set the CRS using the proj4string function.

To learn more about coordinate reference systems and how to set them for your own data, check out:

We can check everything is working by visualizing our data.

Everything is looking good, although we just see the points for now. Now let’s try plotting the points overtop some map features.

2. Mapping using ggmap

The ggmap package is a nice way to plot points, polygons, and lines on top of Google’s (and other sources’) map tiles (eg. satellite or terrain). It follows the same language as ggplot (“gg” stands for “Grammar of Graphics”). This is one way to approach to mapping spatial data in R, but there are many other options, such as Rgooglemaps and maptools.

Lets create some maps with our spatial points.

Before we get started on making a map, we need to convert our SpatialPointsDataFrames into latitude and longitude for ggmap using the spTransform function.

The next step to creating our map is to download the tiles for the study area using the get_map (for Google) or get_stamenmap (for Stamen) functions in the ggmap package. The get_map function requires:

  • location,
  • source,
  • zoom, and
  • maptype

The location can be the latitude and longitude, or a character string describing where you want your map centered. The zoom argument is an integer from 3 (continent) to 21 (building), with a default of 10 (city). To see the options of other source and maptype arguments, type ??get_map into R.

For get_stamenmap function, you need to set:

  • bbox (stands for bounding box; the corners of the extent), and
  • maptype (Stamen does not have satellite imagery)

Not that we’ve downloaded the tiles, let’s make a basic map using the ggmap function

If you’re using Google tiles (you need a key first), the location argument can take a vector with longitude and latitude, or a character string. For the get_stamenmap function, you need a bounding box (bbox).

Let’s download the tiles for Trent University campus.

Let’s build on our basic map and add our point relocations for each animal (connected by a line).

Looking good! You will have to adjust the zoom level of the basemap depending on how far apart your features are.

I hope someone finds this useful! In upcoming posts, I will:

  • construct home ranges in R with minimum convex polygons and kernels,
  • create and analyze differences in animal trajectories.