Creating plot for Residuals using ggplot
08:12 10 Nov 2025

I have following linear regression model

library(nlme)
library(lattice)
data(Orthodont)
model = lm( distance ~ age * Sex, Orthodont)
lattice::bwplot(getGroups(Orthodont) ~ resid(model))

However I want to create the plot for residuals like above, based on ggplot2. Below is an example how my plot should like below.

However my final plot should be horizontal as my previous plot based lattice::bwplot (not vertical). Could you please share some guidance how can I achieve that?

enter image description here

r ggplot2