Visualizing data from the Sleep Cycle phone app in R.
Export the Sleep Cycle data and place it in the project location. In the app, go to Settings > Advanced > Database > Export Database. Input your email address. Once you receive the email, save the "sleepdata.csv" attachment in the same location as these project files.
In RStudio, load the sleep.Rmd R Markdown file. Click the "Knit HTML" button to generate the HTML file containing your sleep charts.
Requires the R library "ggplot2". If necessary, install by running the R command install.packages("ggplot2")
(only needs to be run once).
-
Sleep Quality by Number of Steps (bars over step ranges)
-
Sleep Quality by Number of Steps (scatterplot with trend line)
-
Sleep Quality by Day of Week
-
Time in Bed by Day of Week
-
Number of Steps by Day of Week
-
sleep.R is the R script that loads and cleans the data from the "sleepdata.csv" file. It is called from the R Markdown file automatically.
-
sleep.Rmd is the R Markdown file that generates the plots. It can be exported to an HTML or PDF file.
-
sleepdata.csv contains sample data. Replace this file with your own data from the phone app.
-
sleepdata.Rproj is the RStudio project file.