The world according to Strava
How to get, munge, and visualize Strava data in R

Good data deserve good visualizations
Strava, a social network where athletes share the data generated from their GPS-ensabled devices (watches, phones, etc.) is amazing. One can see the workouts of famous athletes like Killian Jornet, follow their friends, and track their own fitness. But what's really cool is all the data that Strava collects. Those phones and GPS watches are recording precise data about location, speed, elevation, etc. every second all over the world, and Strava is bringing it all under one roof.
Good data deserve good visualizations. So, we thought it'd be cool to visualize some Strava data using R. Here's how we did it.
Get API access
First things first: in order to get access to Strava data, you'll need to go through the Strava API. This means creating an account, and then setting up an "application" on the API page.

Use the rStrava package
Once you've got API access, you can access Strava data just about any way you'd like. We like Marcus Beck's rStrava package for its handling of tokens, helper utilities, and overall usefulness.
Get data
We wanted lots of data, but didn't really care who it came from. So, we wrote some code (below) to fetch random activities, setting a timer so as to not exceed Strava's rate limits (30,000 per day). We let our code run for a few days until we got to 100,000 total activities:
Munge data
Before we're ready to visualize, we need to do a bit of processing. We remove suspiciously long and straight activities (apparently, some people turn on their GPS watch on airplanes), and we use polygonal overlay to get the country and nearest city of each activity. The code (below) is nothing terribly complicated, but necessary, since a few stray datapoints can really mess up a pretty map.
Visualize data
Once we've retrieved and prepared our data, time for the fun - maps!
First, we define a function for plotting the activities of just one country or city (doing more than that results in slow run-time and huge files):
Our visualization function, defined above, creates a leaflet map of all the activities in a country or city. Now let's run it for a few locations and see the results.


Using the leaflet library, we can also produce interactive visualizations.
Cool, huh? Here's all the code for the production of these maps. Enjoy!