Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- weight <- read.csv("~/selfexperiment/weight.csv", colClasses=c("Date", rep("numeric", 7)))
- weight <- weight[weight$Date>=as.Date("2014-10-08") & weight$Date<=Sys.Date(),]
- head(weight)
- ## Date Weight.kg Weight.BMI Weight.body.fat.percent Weight.muscle.percent Weight.resting.metabolism.kcal Weight.body.age.years
- ## 820 2014-10-08 89.04 27.6 27.1 35.5 1897 53
- ## 821 2014-10-09 88.95 27.5 27.9 35.0 1892 53
- ## 822 2014-10-10 88.22 27.2 28.6 34.5 1876 53
- ## 823 2014-10-11 88.68 27.3 28.8 34.4 1881 53
- ## 824 2014-10-12 89.09 27.6 28.3 34.8 1895 54
- ## 825 2014-10-13 90.58 27.8 28.7 34.6 1904 54
- ## Weight.visceral.fat.scale
- ## 820 10
- ## 821 10
- ## 822 10
- ## 823 10
- ## 824 10
- ## 825 10
- # daily weight gain/loss
- weight$Weight.kg.dailydelta <- c(NA, diff(weight$Weight.kg, lag=1))
- # absolute muscle & fat changes
- weight$Weight.muscle.kg <- weight$Weight.kg * (weight$Weight.muscle.percent / 100)
- weight$Weight.body.fat.kg <- weight$Weight.kg * (weight$Weight.body.fat.percent / 100)
- dailytodo <- read.csv("~/selfexperiment/dailytodo.csv", colClasses=c("Date", rep("numeric", 8)))
- workout <- dailytodo[!is.na(dailytodo$Workout) & dailytodo$Workout,]$Date
- weight$Workout <- weight$Date %in% workout
- weight <- aggregate(cbind(Weight.kg, Weight.kg.dailydelta, Weight.body.fat.percent, Weight.muscle.kg, Weight.muscle.percent, Weight.body.fat.kg) ~ Date, mean, data=weight)
- # Workout on day N will only affect day N+1's weight data, so shift down:
- weight$Workout.previous <- (weight$Date %in% (workout+1))
- summary(weight)
- ## Date Weight.kg Weight.kg.dailydelta Weight.body.fat.percent Weight.muscle.kg Weight.muscle.percent
- ## Min. :2014-10-09 Min. :82.07500 Min. :-1.450000000 Min. :21.67500 Min. :29.56332 Min. :32.50000
- ## 1st Qu.:2015-08-07 1st Qu.:89.09000 1st Qu.:-0.135000000 1st Qu.:28.20000 1st Qu.:31.04194 1st Qu.:33.66667
- ## Median :2016-06-28 Median :92.80000 Median : 0.000000000 Median :29.40000 Median :31.49510 Median :34.15000
- ## Mean :2016-07-02 Mean :91.81702 Mean : 0.001386556 Mean :29.00896 Mean :31.51515 Mean :34.35200
- ## 3rd Qu.:2017-05-23 3rd Qu.:94.21500 3rd Qu.: 0.133333333 3rd Qu.:30.20000 3rd Qu.:31.97816 3rd Qu.:34.80000
- ## Max. :2018-04-11 Max. :98.06667 Max. : 1.540000000 Max. :32.03333 Max. :33.79257 Max. :38.57500
- ## Weight.body.fat.kg Workout.previous
- ## Min. :18.10410 Mode :logical
- ## 1st Qu.:25.23316 FALSE:980
- ## Median :27.40273 TRUE :196
- ## Mean :26.68223 NA's :0
- ## 3rd Qu.:28.35467
- ## Max. :30.81967
- library(ggplot2)
- library(gridExtra)
- ephedrine <- geom_vline(xintercept=as.integer(as.Date("2017-11-22")), color="green")
- gym <- geom_vline(xintercept=as.integer(as.Date("2017-10-19")), color="blue")
- gym2 <- geom_vline(xintercept=as.integer(as.Date("2017-12-16")), color="blue2")
- p1.1 <- qplot(Date, Weight.kg, color=Workout.previous, data=weight) + stat_smooth(aes(group=1)) + theme(legend.position = "none") + ephedrine + gym + gym2
- p1.2 <- qplot(Date, Weight.kg.dailydelta, color=Workout.previous, data=weight) + stat_smooth(aes(group=1)) + theme(legend.position = "none") + ephedrine + gym + gym2
- p2.1 <- qplot(Date, Weight.body.fat.percent, color=Workout.previous, data=weight) + stat_smooth(aes(group=1)) + theme(legend.position = "none") + ephedrine + gym + gym2
- p2.2 <- qplot(Date, Weight.body.fat.kg, color=Workout.previous, data=weight) + stat_smooth(aes(group=1)) + theme(legend.position = "none") + ephedrine + gym + gym2
- p3.1 <- qplot(Date, Weight.muscle.percent, color=Workout.previous, data=weight) + stat_smooth(aes(group=1)) + theme(legend.position = "none") + ephedrine + gym + gym2
- p3.2 <- qplot(Date, Weight.muscle.kg, color=Workout.previous, data=weight) + stat_smooth(aes(group=1)) + theme(legend.position = "none") + ephedrine + gym + gym2
- # grid.arrange(p1, p2.1, p2.2, p3.1, p3.2, ncol=1)
- grid.arrange(p1.1, p1.2, p2.1, p2.2, p3.1, p3.2, ncol=1)
Add Comment
Please, Sign In to add comment