问题是,stat_regline_equation
不会继承geom_smooth
的公式,你还必须明确地告诉stat_regline_equation
,你想要一个没有拦截的模型:
注意:作为参考,我为一个有截距的模型添加了geom_smooth
,这表明geom_smooth
已经像你说的那样了.
library(tidyverse)
library(ggpubr)
mtcars %>%
ggplot(aes(disp, hp)) +
geom_point() +
geom_smooth(method = "lm", formula = y ~ x, color= "black", se = FALSE) +
geom_smooth(method = "lm", formula = y ~ x + 0) +
stat_regline_equation(label.y = 300, formula = y ~ x + 0) +
stat_cor(label.y = 250) +
theme_bw()