Skip to content

Instantly share code, notes, and snippets.

@Tafkas
Last active August 31, 2018 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Tafkas/7794142 to your computer and use it in GitHub Desktop.
Save Tafkas/7794142 to your computer and use it in GitHub Desktop.
Chart your data from http://trendweight.com/export with ggplot2 in R
#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