Drawing only boundaries of stat_smooth in ggplot2

ggplot2, plot, r, regression

Solution

You can also use `geom_ribbon` with `fill` = NA.

gg <- ggplot(mtcars, aes(qsec, wt))+
        geom_point() +  
        stat_smooth( alpha=0,method='loess')

rib_data <- ggplot_build(gg)$data[[2]]

ggplot(mtcars)+
  stat_smooth(aes(qsec, wt), alpha=0,method='loess')+
  geom_point(aes(qsec, wt)) +  
  geom_ribbon(data=rib_data,aes(x=x,ymin=ymin,ymax=ymax,col='blue'),
                fill=NA,linetype=1) 

...and if for some reason you don't want the vertical bars, you can just use two `geom_line` layers:

ggplot(mtcars)+
    stat_smooth(aes(qsec, wt), alpha=0,method='loess')+
    geom_point(aes(qsec, wt)) + 
    geom_line(data = rib_data,aes(x = x,y = ymax)) + 
    geom_line(data = rib_data,aes(x = x,y = ymin))

Problem

When using `stat_smooth()` with `geom_point` is there a way to remove the shaded fit region, but only draw its outer bounds? I know I can remove the shaded region with something like: ``` geom_point(aes(x=x, y=y)) + geom_stat(aes(x=x, y=y), alpha=0) ``` but how can I make the outer bounds of it (outer curves) still visible as faint black lines?

Original source