[R] lme: Plot colours based on variable?
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Tue Dec 2 12:06:40 CET 2025
On 2025-12-02 3:39 a.m., Leo Mada via R-help wrote:
> 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?
plot(BodyWeight, ...)
dispatches to plot.nfnGroupedData(), which uses lattice::xyplot()
graphics rather than base graphics. I don't know lattice well enough to
answer your question, but maybe this will give you a hint...
Duncan Murdoch
More information about the R-help
mailing list