Last active
August 31, 2018 18:09
-
-
Save Tafkas/7794142 to your computer and use it in GitHub Desktop.
Chart your data from http://trendweight.com/export with ggplot2 in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#read data | |
tw <- read.csv(file="TrendWeightData.csv",header=T) | |
summary(tw) | |
#remove interpolated values | |
tw <- tw[tw$WeightIsInterpolated == "False",] | |
#convert strings to date and extract year | |
tw$Date <- as.POSIXlt(as.character(tw$Date), format="%Y-%m-%d") | |
tw$Year <- tw$Date$year + 1900 | |
#just take weights until June 5th 2013 | |
tw <- tw[tw$Date < as.POSIXlt("2013-06-06"),] | |
library("ggplot2") | |
p <- ggplot(tw, aes(Date, WeightActual)) + theme_bw() | |
p <- p +geom_point(aes(colour=FatPercentActual)) + scale_colour_gradient(limits=c(17, 31), low="green", high="red", guide_legend(title = "Body Fat Percentage")) | |
p <- p + ggtitle("Body Weight 2008-2013") + ylab("Body weight in kg") + geom_smooth() | |
p | |
p <- ggplot(tw, aes(WeightActual, FatPercentActual)) + theme_bw() | |
p <- p + geom_point() + geom_smooth(method=lm, col="red") #aes(colour=as.factor(Year))) | |
p <- p + ggtitle("Body Weight vs. Body Fat Percentage") + xlab("Body Weight in kg") + ylab("Body Fat Percentage") | |
p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment