[R] lme: Plot colours based on variable?

Leo Mada |eo@m@d@ @end|ng |rom @yon|c@eu
Tue Dec 2 09:39:09 CET 2025


Dear R-Users,

Is there a quick solution to plot colours based on a variable?

I tried something like this:

library(nlme)

plot(BodyWeight)

# Does NOT work!
colDiet = c(2:4)[BodyWeight$Diet]
plot(BodyWeight, col = colDiet)

# Wastes space
rat.fit = lme(weight ~ Time + Diet, data = BodyWeight, random = ~ Time|Rat)
plot(rat.fit, weight ~ Time | Rat + Diet)

Is there a quick way to base the colour on the Diet variable?

Many thanks,

Leonard


	[[alternative HTML version deleted]]



More information about the R-help mailing list