You can calculate the empirical residue densities for cuts along a set line. Then itβs just a matter of drawing lines at your chosen positions in each interval using geom_path . To add a theoretical distribution, create some densities over the range of residuals for each section (here, using the normal density). For normal densities below, the standard deviation for each of them is determined for each section from the residuals, but you can simply select the standard deviation for all of them and use this instead.
#

Or, only gaussian curves
## Just normal ggplot(dat, aes(x, y)) + geom_point() + geom_smooth(method="lm", fill=NA, lwd=2) + geom_path(data=dens[dens$type=="normal",], aes(x, y, group=section), color="salmon", lwd=1.1) + theme_bw() + geom_vline(xintercept=breaks, lty=2)

jenesaisquoi
source share