I've found using stat_regline_equation
(with ggscatter
) to be really useful for quickly adding regression equations to plots, especially when I having multiple regressions on multiple facets. However, it seems to be stuck on 2 significant figures for terms. I know it is possible to extract coefficients from an lm
and then display them with annotate. But with multiple facets that seems really daunting and finicky. Is there possibly a feature in the works (or already here, that I don't know about) to do this with stat_regline_eq
? I have hope because you can specify digits with stat_cor
for things like r-square and p-values! Any advice or help would be appreciated. Reproducible example below:
library(tidyverse)
library(ggpubr)
ggscatter(diamonds, x="carat", y="table", add="reg.line") +
facet_wrap(~color) +
stat_regline_equation(label.y=90)
summary(lm(table ~ carat, data=filter(diamonds, color=="D")))
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 56.46453 0.05438 1038.3 <2e-16 ***
carat 1.42911 0.07255 19.7 <2e-16 ***
As you can see, the intercept shown in ggscatter
for D is off by 0.5.