This is now implemented in package 'ggpmisc' in GitHub (future version 0.4.4), but not yet in version 0.4.3 available in CRAN. This does not do exactly what you asked as at the moment geom_poly_eq()
does not return R as it is not meaningful for polynomials of higher order than 1. Keeping to the grammar of graphics paradigm allows easier customization at the cost of lengthier code than the all-in-one functions from package pubr
. Each approach has its advantages and drawbacks. I show here three examples of different possible approaches using package 'ggpmisc' (together with 'ggplot2').
library(ggpmisc)
#> Loading required package: ggpp
#> Loading required package: ggplot2
#>
#> Attaching package: 'ggpp'
#> The following object is masked from 'package:ggplot2':
#>
#> annotate
# First approach: faint lines for non-significant fits, with bands
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_eq(aes(label = paste(after_stat(rr.label),
after_stat(p.value.label),
sep = "*\", \"*")),
label.x = "right") +
stat_poly_line(aes(colour = stage(after_scale = ifelse(p.value < 0.05,
alpha(colour, 1),
alpha(colour, 0.25)))),
se = TRUE,
mf.values = T) +
facet_wrap(~class, ncol = 2) +
theme_bw()

# Second approach: faint lines for non-significant fits, no-bands
# colour mapped to class
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = class)) +
stat_poly_eq(aes(label = paste(after_stat(rr.label),
after_stat(p.value.label),
sep = "*\", \"*")),
label.x = "right") +
stat_poly_line(aes(colour = stage(start = class,
after_scale = ifelse(p.value < 0.05,
alpha(colour, 1),
alpha(colour, 0.25)))),
se = FALSE,
mf.values = T) +
facet_wrap(~class, ncol = 2) +
theme_bw()
#> Warning: Failed to apply `after_scale()` modifications to legend

# Third approach: no bands or lines for non-significant fits
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = class)) +
stat_poly_eq(aes(label = paste(after_stat(rr.label),
after_stat(p.value.label),
sep = "*\", \"*")),
label.x = "right") +
stat_poly_line(aes(colour = stage(after_scale = ifelse(p.value < 0.05,
colour,
NA)),
fill = stage(after_scale = ifelse(p.value < 0.05,
fill,
NA))),
se = TRUE,
mf.values = T) +
facet_wrap(~class, ncol = 2) +
theme_bw()
#> Warning: Duplicated aesthetics after name standardisation: NA
#> Warning: Failed to apply `after_scale()` modifications to legend

Created on 2021-09-07 by the reprex package (v2.0.1)