Instead of pairing with geom_segment() and combining the stat with geom_point(), we want to have a line and a point in a single layer. Repurpose the Stat class and constructor to work with geom_pointrange() instead.
You can use after_stat() to set ymin to the fitted computed variable and ymax to y.
StatResidual <-ggproto("StatResidual", # class name Stat, # parentcompute_group = residual_lines,default_aes =aes(ymin =after_stat(fitted),ymax =after_stat(y) ))stat_residual <-make_constructor(StatResidual, geom ="pointrange")p +stat_residual()