在 ggplot2 (R Studio) 中,有没有办法将回归线延伸到绘图的末尾而不是最后一个数据点

In ggplot2 (R Studio), is there a way to extend the regression lines to the end of the plot rather than the last data point

我是 R & ggplot 的新手。我正在尝试绘制交互。当我使用 SPSS 绘制交互时 - 回归线从 y 轴一直到绘图的相对边缘:

但是,当我使用 ggplot 时,回归线只延伸到第一个和最后一个数据点,这使得图表看起来很奇怪

有什么方法可以解决这个问题并使我的 ggplot 看起来更像 SPSS 图吗?

这是我使用的代码

No5Plot <- ggplot(data=pccdata, aes(x= factor2, y = pcc, color = Factor.1)) +
  geom_point(size=1.2) +
  theme_classic() +
  geom_smooth(method = "lm", se = F) +
  labs(x = "Factor 2", y = "Posterior Cingulate Cortex \n Gyrification")
No5Plot + scale_color_manual(values = c("#CC79A7", "#009E73", "#0072B2")) + 
    theme(axis.title = element_text(size = 20), axis.text = element_text(size=15))

geom_smooth 有一个 fullrange 选项,其默认值为 FALSE:

Should the fit span the full range of the plot, or just the data?

因此,您可以使用:

geom_smooth(method = "lm", se = FALSE, fullrange = TRUE)