I have looked at How to obtain multiple colours for geom_line conditional on a specific value
and I am wondering/hoping that I can get some help with a related problem i.e. how to change the colour of geom_line()
depending on a the level of a third factor. So I have a cross-over design for a treatment. Each individual (Specified as IDNUm) has two treatments in random order (Treat: levels = "Q", "S") and results of outcomes measured at three consecutive visits (Visit: levels = "B","T1","T2"). So I want to plot an outcome (Result) at each of the time points connected by a line which changes colour depending on what treatment they have had in that interval (i.e. B(aseline) to T1, and T1 to T2).
ggplot(s,aes(x=Visit,y=Result,group=IDNum,colour=Treat))+geom_line()
gives me a plot where the line colour is defined by the first treatment only and doesn't change for the second interval