My Activities in 2018 with R and ShinyApp

What better way to analyze your activities data from Apple Health and Runkeeper into R and generating some visualizations and counters. After that I will wrapping it together into a Shiny App.

What do I want to achieve for now?

  • Number of activities, steps, kilometers ect.
  • Heatmap of last X years number of activities colored by amount.

Loading and have a look at the data

Export Runkeeper data, the option is available after login > account settings > export data > download your data.

For export and convert your Apple Health data follow my previous post Analysing your Apple Health Data with Splunk.

From the Runkeeper data we need Date and from Apple Health StepCount we need the endDate (thats when your step is done). Both has type chr. I could convert it as date, but I leave the data what it is and will do convert it when necessary.

Create new variables

First we load the lubridate package.

I will create some new variables and convert Date and endDate as Date so I can extract the year with the year function of the lubridate package.

As you can see in the above summary of both dataframes, Runkeeper has more years than steps. That doesn’t matter becouse we are now only looking for 2018 in the Shiny App and I will group it by year. In the app I create a year slider.

I will parse the period with hour, minuts ans seconds of the variable Duration. And I will calculate the duration in minutus. Some of the Duration variables has no leading zero for the hour and I cannot use it with the function hms.

Add a leading zero if not exists.

Now I can parse the Duration with hms.

Group the data by year

First we load the package dplyr.

Group both dataframes by year and do some summarises like count and sum of kilometers, climb, calories and duration

Some simple visualizations

plot of chunk unnamed-chunk-8

plot of chunk unnamed-chunk-8

Add a heatmap of number of activities last 3 years from now.

plot of chunk unnamed-chunk-9

Screenshot Shiny App


Well wrap it up into a Shiny App which can be found on my GitHub.

3 comments on “My Activities in 2018 with R and ShinyApp”

  1. dominik Koch says:

    Great post. You might want to check my Calender Heatmap that i wrote in ggplot2. It allows to track your activities on a daily basis

    1. jletteboer says:

      Hi Dominik, Thanks, I will definitely check and try it.

Comments are closed.

Related Posts