79815631

Date: 2025-11-10 13:15:34
Score: 1
Natty:
Report link

I would do it like this:

library(ggplot2)
library(nlme)
data(Orthodont)

model <- lm(distance ~ age * Sex, data = Orthodont)
Orthodont$resid <- resid(model)

ggplot(Orthodont, aes(x = as.factor(age), y = resid, fill = Sex)) +
  geom_boxplot(alpha = 0.6) +
  coord_flip() +
  labs(
    x = "Age",
    y = "Residuals",
    title = "Residuals by Age",
    subtitle = "Colored by Sex (Equivalent to lattice::bwplot)"
  ) +
  theme_minimal() +
  scale_fill_manual(values = c("steelblue", "tomato"))

enter image description here

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: monk