Monday, June 4, 2012

Lexis Plot

boxplots as alternative to barplot with error bars

  • thX is a Lexis object (Epi package)
  • in the dead variable is coded wether the subjects died or not
  • in the injstat variable is coded which status the subject had when it entered a specific period (defined by age and time)
  • in lex.Xst the exit status is coded
## plot lines for all subjects in a light colour
plot(thX,2:1,col=c("azure2","red")[factor(thX$dead)],xlab="year")
## for the dead subjects we set the line width 2, for all other subject 0 so we do not see them
## we set color for the treatment time red and time after treatment blue
lines(thX,2:1,col=c("red","blue")[factor(thX$injstat)],
      lwd=c(0,2)[factor(thX$dead)])

## we add big white crosses at the point of dead
points(thX,2:1,pch=c(NA,NA,NA,3)[factor(thX$lex.Xst)],
       col="white",lwd=3,cex=1.2)
## within these big white crosses we plot coloured crosses which indicates the risk group of the subjects
points(thX,2:1,pch=c(NA,NA,NA,3)[factor(thX$lex.Xst)],
       col=c("green","green","blue","red")[factor(thX$riskgroup)],lwd=1,cex=1)

## add a legend
text(rep(2016,2),c(27.5,25.5),c("treatment","after treatment"),
     col=c("red","blue"),pos=4)

points(rep(2015,3),c(34.5,32.5,30.5),
       pch=3,lwd=3,cex=1.2,col="lightgrey")
points(rep(2015,3),c(34.5,32.5,30.5),pch=3,
       lwd=1,cex=1,col=c("green","blue","red"))
text(rep(2016,3),c(34.5,32.5,30.5),
     c("riskgroup 1a, 1b","riskgroup 2","riskgroup 3"),
     col=c("green","blue","red"),pos=4)

0 comments:

Post a Comment