Regular Running

As someone who’d hoped to run 1,000 miles this year (Update/Spoiler Alert: I’m going to fall about 80 miles short), I have a regular running route that I follow.

My most common run is the one I do during the week, during my lunch or some time in the afternoon, around the campus of Georgia Tech. This is a pretty popular urban ‘trail’ known as the Pi Mile and I can extend it from 5k to around 7k by running a bit longer on 10th Street, depending on the amount of time I have on any given day.

After doing some detective work using SmashRun, I determined that I’ve run this route 59 times in 2016!

I did a little bit of file conversion and “wrote” some additional code since my last mapping project, and ended up with some fun visualizations of all that data.

Here, then, are variations of a heat map of all my Pi Mile runs in 2016:

Here’s the actual source code I used myself to create all the maps above:

library(plotKML)
library(ggplot2)
library(ggmap)

# GPX files downloaded from Runkeeper
files < - dir(pattern = "\\.gpx")

# Consolidate routes in one drata frame
index <- c()
latitude <- c()
longitude <- c()
for (i in 1:length(files)) {
    
  route <- readGPX(files[i])
  location <- route$tracks[[1]][[1]]
  
  index <- c(index, rep(i, dim(location)[1]))
  latitude <- c(latitude, location$lat)
  longitude <- c(longitude, location$lon)
}
routes <- data.frame(cbind(index, latitude, longitude))

# Map the routes
ids <- unique(index)
plot(routes$longitude, routes$latitude, type="n", 
axes=FALSE, xlab="", ylab="", main="", asp=1)
for (i in 1:length(ids)) {
  currRoute <- subset(routes, index==ids[i])
  lines(currRoute$longitude, currRoute$latitude, col="#0066FF20")
}

# Plot over map of campus
GnatsMap <- qmap(location = 'Georgia Institue of Technology, Atlanta', 
zoom = 15, maptype = 'satellite', source = 'google')

GnatsMap +
  geom_path(aes(x = longitude, y = latitude, group = factor(index)), 
  colour="#1E2B6A", data = routes, alpha=0.3)

All the GPX files (which you can get from Strava) need to be in one directory when you run the script in R.

To change the color of the routes, modify this hex value:

for (i in 1:length(ids)) {
  currRoute < - subset(routes, index==ids[i])
  lines(currRoute$longitude, currRoute$latitude, col="#0066FF20")
}

To change the underlying map, change this portion:

qmap(location = 'Georgia Institue of Technology, Atlanta', zoom = 15, 
maptype = 'satellite', source = 'google')

Many thanks to the code of Saul Torres-Ortega and Frazier at UCSB.

Refer back to this PDF if you need additional help fussing with the underlying map. If the parsing of the GPX files is the issue, I’d look at the original code I borrowed.

One of the things that jumps out at me, if you look solely at the heat map (without geo data), is that the data is really noisy where/when I start my runs (upper right side). As you can imagine I’m not running across 75/85 in Midtown Atlanta, but that’s what the data shows.

Probably just the nature of tracking GPS with a phone, but the fidelity of the rest of the data seems solid. You can tell at one point when I’m choosing to run on one side of the sidewalk versus the other (lower right side, near Bobby Dodd) and the rare occasions – when I extended a 5k/7k into something more like a 10k – those are the thinner, lighter lines on 10th Street and some of the streets interior to tech’s campus (mostly left side of the map).

If you want to see another cool visualization of the same area of midtown using public running data from Strava from 2015, it’s also pretty cool.

Until next time, Run Happy!

Leave a Reply

Your email address will not be published. Required fields are marked *