Skip to content
Prev 279599 / 398506 Next

plotting and coloring longitudinal data with three time points (ggplot2)

On 12/07/2011 08:02 PM, Eric Fail wrote:
Hi Eric,
Try this, I think it does more or less what you want. I tried to work 
this out with matplot, but couldn't.

library(plotrix)
df2<-data.frame(dates=c(base_dates,dates2,dates3),patients=rep(LETTERS,3),
  occasion=rep(c("Assessment","Treatment","Hospital"),each=26))
plot(df2$dates,as.numeric(factor(df2$patients)),
  main="Dates of treatment stages by patient",
  xlab="Date",ylab="Patient",axes=FALSE,pch=rep(c("A","T","H"),each=26))
axis.dates<-c("2011-01-01","2011-03-01","2011-05-01","2011-07-01",
  "2011-09-01","2011-11-01")
axis(1,at=as.Date(axis.dates,"%Y-%m-%d"),labels=axis.dates)
staxlab(2,at=1:26,labels=LETTERS)
box()
for(i in 1:26) {
  lines(df2$dates[c(i,i+26)],c(i,i),col=2)
  lines(df2$dates[c(i+26,i+52)],c(i,i),col=3)
}

Jim