This short R code snippet is written to process GPS coordinate and heart beat rate files, such as recorded by Garmin Forerunner 405 sports watch. The idea is to take the data and present it in a nice card-like format, which allows obtaining all interesting information about the run with a simple glance.
The output is an image file with the following information:
- WEEKDAY (DATE @ TIME)
- Total distance: DIST
- Total time: TIME
- Average pace: PACE
and an OpenStreetMap map with overlayed GPS coordinates (dots) plus three plots: altitude vs. distance, pace vs. distance and heart rate vs. distance. On the map, GPS coordinates matching most closely to full kilometers are highlighted with numbers.
Note that the distance information is accurately calculated with the ellipsoidal formula by Thaddeus Vincenty (the Earth is not a ball, after all) and includes a correction which takes altitude differences into account (I run close to the Alps, altitude differences can be several hundreds of meters during one run).
For pace, the individual data points are way too noisy. So, the pace is calculated separately for every 100 m trek, which seems to give reasonably trustworthy values.
The original inspiration for this code came from Mollie Taylor's blog.
Required R packages
- Cleaning up the code (it's a mess right now)
- Checks for the input parameters, files, etc.
runmap.R -i gpsdata.csv -t svg -o outfile.svg
On obtaining the GPS data
At the moment, the code assumes that the data is given in csv format. To get it from the Garmin, I use python-ant-downloader by Braiden Kindt, which gives me tcx data, which I then convert with gpsbabel with the following command
gpsbabel -t -i gtrnctr -f gpsdata.tcx -o unicsv -F gpsdata.csv
gpsdata.tcx is the file from
is the new file to be fed to
This code has been written by Jani Kotakoski email@example.com and is provided in the hope that it will be useful also for others.
Licence and copyright
Copyright 2014 Jani Kotakoski, released under the MIT License (see LICENSE.txt).