Skip to content

Instantly share code, notes, and snippets.

@Sonictherocketman
Created August 29, 2022 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sonictherocketman/54ac8666460ec5c121f9d5da1ab139c2 to your computer and use it in GitHub Desktop.
Save Sonictherocketman/54ac8666460ec5c121f9d5da1ab139c2 to your computer and use it in GitHub Desktop.
A script to process and chart step count data exported from Pedometer++ for iOS.
#! /usr/bin/env Rscript
library(zoo)
raw_data = read.csv('Export.csv')
raw_data$Date <- as.Date(raw_data$Date, "%m/%d/%y")
readings = data.frame(
dates=raw_data$Date,
steps=raw_data$Steps
)
readings = subset(readings, dates > "2012-01-01" )
readings.steps = read.zoo(readings, drop = FALSE)
readings$rolling_average <- rollmean(
readings.steps$steps,
30,
partial=TRUE,
fill=NA,
align="left"
)
mean_line <- rep(mean(readings$steps), length(readings$steps))
is_streak <- function(x) {return(if (x > 6500) 10 else NA)}
# Output Setup
png(
"step-counts.png",
width = 1600,
height = 900,
)
par(bg = 'white')
par(mar = c(5, 4, 4, 4) + 0.3)
# Plots
plot(
mean_line,
axes=FALSE,
bty='n',
xlab="",
ylab="",
type='l',
col='orange3',
lwd=3.0,
ylim=c(0, max(readings$steps) + 20)
)
par(new = TRUE)
plot(
readings$dates,
readings$steps,
xlab="",
ylab="",
col='blue3',
type='l',
lwd=2.0,
ylim=c(0, max(readings$steps))
)
mtext("Steps (blue)", line=3, side=2)
mtext("Date", line=3, side=1)
par(new = TRUE)
plot(
readings$dates,
readings$rolling_average,
axes=FALSE,
bty='n',
xlab="",
ylab="",
col='green4',
lwd=2.0,
cex=0.6,
pch=21,
bg="green",
ylim=c(0, max(readings$steps) + 20)
)
par(new = TRUE)
plot(
readings$dates,
sapply(readings$steps, FUN=is_streak),
axes=FALSE,
bty='n',
xlab="",
ylab="",
type='l',
col='red3',
lwd=3.0,
ylim=c(0, max(readings$steps) + 20)
)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment