This repository contains R scripts to import, clean, and visualise Apple Health data.
So far it imports the raw file (export.xml), parses it into tidy CSV files and creates interactive plots to explore your activity distribution.
More functions will follow such as other graphs for other data nodes, inference, trend analysis and forecasting, etc.
- Open the Health app on your iPhone.
- Tap profile picture → Export Health Data.
- Save the exported
export.zip.
Once unzipped, the resulting folder will contain these files:
-
export.xml— the main XML file containing nearly all your Apple Health data (heart rate, workouts, activity summaries, etc.). -
export_cda.xml— a duplicate of your data in Clinical Document Architecture (medical admin standard) format.
And possibly other folders depending on device usage, e.g., sleep or mindfulness data. A few examples :
-
electrocardiograms/— ECG data. -
workout-routes/— GPS route data for workouts.
In this project, I focused on export.xml for readability and reproducibility.
Put export.xmlin apple-health-data/data/export.xml.
Run r source("01_import_health_data.R")
It will :
- Parse the XML export.
- Select nodes of interest. Mine were "Workout", "WorkoutStatistics", and "ActivitySummary".
- Convert them into tidy tibbles.
- Transform date strings into R date-time objects.
- Transform numeric strings into floats.
- Remove unnecessary prefixes in activity names (
HKWorkoutActivityType). - Save cleaned CSVs in
data/.
Run r source("02_visualise_health_data.R")
It will :
- Load the cleaned CSV files (
health_data_workout.csv,health_data_workoutstatistics.csv,health_data_activitysummary.csv). - Generate interactive plots using ggplot2 and plotly.
- Display distributions of workout types directly in R.
xml2, dplyr, purrr, lubridate, readr, vroom, ggplot2, plotly, htmlwidgets, viridis, forcats
Install with : r install.packages(c("xml2","dplyr","purrr","lubridate","readr","vroom","ggplot2","plotly","htmlwidgets","viridis","forcats")).