Reports

To visualize the collected data i use R and knitr. R has very convenient statistical tools and powerful graphics. knitr creates from the R output a nice HTML page.
The original idea was to analyse HRV data and R is an adequate choice for this. But because i am not doing any intensive training and recovery is not my problem the only variable influencing my decisions is my weight. The flexibility of my setup is still handy. I find myself quite often modifying the reports to match my interests.
The main R/knitr program is:


Weight tracking `r date()`
==============================

```{r echo=F,warning=F,highlight=T}
library("lubridate")
options(width=100)
old.t=trellis.par.set(theEconomist.theme(box = "transparent"))
old.l=lattice.options(theEconomist.opts())
trellis.par.set(reference.line=list(lwd=0.3))
opts_chunk$set( fig.width=12, fig.height=7, tidy=F, error=T, warning=T)
```

Regression line for last 4*7 days <b style="color:blue">blue</b>,
7 days <b style="color:red">red</b>.

```{r weight,echo=F,fig=T}
weight=read.table( file="data/weight.csv", sep=" ", header=T)
weight$date = as.POSIXct( weight$date, format="%Y-%m-%dT%H:%M:%S" )
wday = wday(weight$date,T)
weight=data.frame( weight,
  wday=factor( wday, levels=c("Mon","Tues","Wed","Thurs","Fri","Sat","Sun")), 
  wend=(wday=="Sat") | (wday=="Sun"))

xlim=c(as.POSIXct("2011-07-01"), Sys.time()+(30*3600*24))

p = function(x,y,...) {
  panel.abline(73.4, 0, col="#eeeeee", lwd=70)
  panel.lmline(tail(x,4*7), tail(y,4*7), col="blue")
  panel.lmline(tail(x,7), tail(y,7), col="red")
  panel.xyplot(x,y,col=ifelse(weight$wend,"red","darkblue"),...)
}
print((xyplot( 
  kg~date, main="Weight", data=weight, panel=p, 
  xlim=xlim, ylim=c(70,96),
  xlab=NULL, ylab=NULL, 
  pch=".", cex="3", type=c("p","smooth"),span=0.1 )))
```

```{r weightdiff,child="weightdiff.Rmd"}
```

```{r sugar,echo=F,fig=TRUE}
sugar = read.table( file="data/sugar.csv",  sep=" ", header=T)
sugar$date = as.POSIXct( sugar$date, format="%Y-%m-%dT%H:%M")
sugar= sugar[ hour( sugar$date)<10 & hour(sugar$date)>5,] #filter: keep morning only

pSugar = function(x,y,...) {
  panel.grid(v=FALSE,h=-1,...)
  panel.xyplot(x,y,...)
}

print((xyplot(
  glu ~ date, main="Sugar", data=sugar, panel=pSugar,
  xlim=xlim, ylim=c(4,8),
  xlab=NULL, ylab=NULL, type=c("p","smooth"), span=0.1)))
```

```{r pressure,echo=F,fig=TRUE}
pressure = read.table( file="data/pressure.csv", sep=" ", header=T)
pressure$date = as.POSIXct( pressure$date, format="%Y-%m-%dT%H:%M:%S")
pressure = pressure[ hour( pressure$date )<10,] #filter: keep morning only

pPressure = function(x,y,...) {
  panel.grid(v=FALSE,h=-1,...)
  #panel.average(trunc(x,"day"),pressure$sys,horizontal=F)
  panel.xyplot(x,y,...)
}

print((xyplot(
  sys+di+fr ~ date, main="Blood pressure", data=pressure, panel=pPressure,
  xlim=xlim,
  xlab=NULL, ylab=NULL, pch=".", cex=3, type=c("p","smooth"), 
  col=c("green","red","black","blue"), span=0.05)))
```

```{r ortho,child="orthostatic.Rmd", eval=F}
```

```{r finish,echo=F}
trellis.par.set(old.t)
lattice.options(old.l)
```

(It references two unimportant include files weightdiff.Rmd and orthostatic.Rmd.)

This script produces this Sample report (converted with wkhtmltopdf).

Leave a comment