I would like to create a plot that looks like this:
I have been trying to do this, but not sure how to do it. So here is my reproducible data:
library(ggplot2)
library(nlme)
mydata <- data.frame(SID=sample(1:150,400,replace=TRUE),age=sample(50:70,400,replace=TRUE), sex=sample(c("Male","Female"),200, replace=TRUE),time= sample(1:3,400, replace=TRUE), Vol =rnorm(400),HCD =rnorm(400))
mydata$time <- as.numeric(mydata$time)
model = lme(Vol ~ age+sex*time+time* HCD, random=~1|SID, na.action="na.omit",data=mydata);summary(model)
gp <- ggplot(mydata, aes(x=age, y=Vol, group=SID))+geom_line(aes(group=time, col=sex))
print(gp)
Unfortunately, this is what I get:
I tried to limit the time points to two points, but still doesn't look great. Any suggestions on how I can improve this?
Many thanks!