Below is the random effects code from the mixed effects model:
mtcarsSub <- mtcars[,c("wt", "drat", "cyl")] library(lme4) mtcarsME <- lmer(drat ~ (1|cyl) + wt, data=mtcarsSub) mtcarsSub$fixed.effect <- predict(mtcarsME) library(plyr) l_ply(list(4, 6, 8), function(x) mtcarsSub[[ paste0("random.effect.cyl", x) ]] <<- mtcarsSub$fixed.effect + ranef(mtcarsME)$cyl[as.character(x),]) library(ggplot2) ggplot(mtcarsSub, aes(wt, drat, color=factor(cyl))) + geom_point() + geom_line(aes(wt, fixed.effect), color="black", size=2) + geom_line(aes(wt, random.effect.cyl4), size=2) + geom_line(aes(wt, random.effect.cyl6), size=2) + geom_line(aes(wt, random.effect.cyl8), size=2)

How can I programmatically make each line of a random effect the same color as the colors displayed for cyl ? Therefore, the line of random effect for level 4 cyl should be red, level 6 of cyl should be green, and level 8 of cyl should be blue. I do not want to specify color="red" , etc. In geom_line() .
source share