I am an avid user of the Strava application. It’s an application on your phone that allows you to track detailed metrics about all you physical activities. Although the application allows you to track many different types of activities, it only provides roll up data for 3 activities, Cycling, Running and Swimming. This bums me out because two activities I capture on a regular basis are Hiking and my Strength Workouts. My bike activities are well represented but perhaps I’d like to see the data in my own way? Strava allows you to download (once per week) all of your personal data as a CSV file. This contains all data from all of your activities as 78 different variables such as distance, speed, date etc. Instead of a nasty spreadsheet exercise let’s use R and have some fun with this. The code below reads the Strava CSV file (as is) and does some basic clean up before creating a data frame. From there you can easily perform basic analysis and plotting. 3 of the plots below are driven by a function which is easy to tune to different variables. The 4th is an example of a dated roll up.

library(tidyverse)
library(janitor)
library(skimr)
library(lubridate)
library(DT)
library(scales)
#read csv file
activities <- read.csv('activities.csv')

#Create a new data frame with clean variable names and dates. Subset data to YTD by activities. After this you can use cleanactivities to do whatever you like with any of the 78 column variables, distance, elevation_gain, date, description etc.
cleanactivities <- activities %>%
  clean_names() %>% 
  #print(activity_type) %>% 
  mutate(activity_date = as.POSIXct(activity_date, format = "%b %d, %Y,%H:%M:%S %p")) %>%
  #For a short time I was logging hikes as runs so I could see the aggregate data in the app. So here I change them to hikes so my totals are accurate.
  mutate(activity_type = str_replace(activity_type, "Run", "Hike")) %>%
  filter(activity_date >= as.Date('2021-01-01')) %>%
  filter(str_detect(activity_type, 'Hike|Ride|Workout'))

#group distances by activity
  dist <- cleanactivities %>% 
  group_by(activity_type) %>% 
  summarise(distance = round(sum(distance) / 1.609)) 
  #print(dist)
#group elevations by activity  
  elev <- cleanactivities %>% 
  group_by(activity_type) %>% 
  summarise(elevation_gain = round(sum(elevation_gain) * 3.281))
  #print(elev)
#group elapsed time by activity
  dur <- cleanactivities %>% 
  group_by(activity_type) %>% 
  summarise(elapsed_time = round(sum(elapsed_time / 60) / 60))
  #print(dur)

Strava variable names

names(cleanactivities)
##  [1] "activity_id"                                                                                  
##  [2] "activity_date"                                                                                
##  [3] "activity_name"                                                                                
##  [4] "activity_type"                                                                                
##  [5] "activity_description"                                                                         
##  [6] "elapsed_time"                                                                                 
##  [7] "distance"                                                                                     
##  [8] "relative_effort"                                                                              
##  [9] "commute"                                                                                      
## [10] "activity_gear"                                                                                
## [11] "filename"                                                                                     
## [12] "athlete_weight"                                                                               
## [13] "bike_weight"                                                                                  
## [14] "elapsed_time_1"                                                                               
## [15] "moving_time"                                                                                  
## [16] "distance_1"                                                                                   
## [17] "max_speed"                                                                                    
## [18] "average_speed"                                                                                
## [19] "elevation_gain"                                                                               
## [20] "elevation_loss"                                                                               
## [21] "elevation_low"                                                                                
## [22] "elevation_high"                                                                               
## [23] "max_grade"                                                                                    
## [24] "average_grade"                                                                                
## [25] "average_positive_grade"                                                                       
## [26] "average_negative_grade"                                                                       
## [27] "max_cadence"                                                                                  
## [28] "average_cadence"                                                                              
## [29] "max_heart_rate"                                                                               
## [30] "average_heart_rate"                                                                           
## [31] "max_watts"                                                                                    
## [32] "average_watts"                                                                                
## [33] "calories"                                                                                     
## [34] "max_temperature"                                                                              
## [35] "average_temperature"                                                                          
## [36] "relative_effort_1"                                                                            
## [37] "total_work"                                                                                   
## [38] "number_of_runs"                                                                               
## [39] "uphill_time"                                                                                  
## [40] "downhill_time"                                                                                
## [41] "other_time"                                                                                   
## [42] "perceived_exertion"                                                                           
## [43] "translation_missing_en_us_lib_export_portability_exporter_activities_horton_values_type"      
## [44] "translation_missing_en_us_lib_export_portability_exporter_activities_horton_values_start_time"
## [45] "weighted_average_power"                                                                       
## [46] "power_count"                                                                                  
## [47] "prefer_perceived_exertion"                                                                    
## [48] "perceived_relative_effort"                                                                    
## [49] "commute_1"                                                                                    
## [50] "total_weight_lifted"                                                                          
## [51] "from_upload"                                                                                  
## [52] "grade_adjusted_distance"                                                                      
## [53] "weather_observation_time"                                                                     
## [54] "weather_condition"                                                                            
## [55] "weather_temperature"                                                                          
## [56] "apparent_temperature"                                                                         
## [57] "dewpoint"                                                                                     
## [58] "humidity"                                                                                     
## [59] "weather_pressure"                                                                             
## [60] "wind_speed"                                                                                   
## [61] "wind_gust"                                                                                    
## [62] "wind_bearing"                                                                                 
## [63] "precipitation_intensity"                                                                      
## [64] "sunrise_time"                                                                                 
## [65] "sunset_time"                                                                                  
## [66] "moon_phase"                                                                                   
## [67] "bike"                                                                                         
## [68] "gear"                                                                                         
## [69] "precipitation_probability"                                                                    
## [70] "precipitation_type"                                                                           
## [71] "cloud_cover"                                                                                  
## [72] "weather_visibility"                                                                           
## [73] "uv_index"                                                                                     
## [74] "weather_ozone"                                                                                
## [75] "translation_missing_en_us_lib_export_portability_exporter_activities_horton_values_jump_count"
## [76] "translation_missing_en_us_lib_export_portability_exporter_activities_horton_values_total_grit"
## [77] "translation_missing_en_us_lib_export_portability_exporter_activities_horton_values_avg_flow"  
## [78] "translation_missing_en_us_lib_export_portability_exporter_activities_horton_values_flagged"

Plot function

#Function plots activities, x = summarized data, metric = miles,hours etc., ylabel is metric name.  
  activityPlot <- function(x, metric, ylabel){
      ggplot(x, aes(activity_type, metric, fill = activity_type)) +
      ggtitle(paste( "Total YTD", ylabel, " =", sum(metric) ) ) +
      theme(plot.title = element_text(size = 20, face = "bold")) +
      geom_col() +
      geom_text(aes(label = metric, y = metric - 10), position = position_stack(vjust = 0.5), size = 10) +
      ylab(ylabel) +
      scale_fill_manual(values=c("#CC6666", "#9999CC", "#66CC99"))
  }

Create plots

activityPlot(dist, dist$distance, "Total Distance In Miles")

activityPlot(elev, elev$elevation_gain, "Total Elevation Gain In Feet")

activityPlot(dur, dur$elapsed_time, "Total Workout Time In Hours")

#A plot to show all my activities by date
ggplot(cleanactivities, aes(cleanactivities$activity_date, round((cleanactivities$elapsed_time / 60)), color = cleanactivities$activity_type )) + 
  ggtitle("Activities By Date") +
  theme(plot.title = element_text(size = 20, face = "bold")) +
  geom_point(size = 3) +
  scale_x_datetime(date_breaks = "month") +
  labs(x = "Date Of Activity", y = "Activity Time In Minutes")