R ggplot - 将多条线性回归线绘制成一个图

R ggplot - plot multiple linear regresssion lines to a single plot

我有 3 种不同的线性回归模型,例如 -lm1, lm2, lm3,它们是使用标准 R lm 创建的,例如

lm1 = loess(df1$y ~ df1$x, span=0.10)
lm2 = loess(df2$y ~ df2$x, span=0.10)
lm3 = loess(df3$y ~ df3$x, span=0.10)

我想使用 ggplot 将这 3 个模型的拟合线放到一个图中。获得如下图的正确方法是什么,每个模型在各自的数据框中都装有输入数据。

每个 df 的 X 和 Y 变量是否相同?如果是这样,你总是可以 rbind() 你的 dfs 并创建另一个变量(例如,df_source)并按照以下方式做一些事情:

'''
ggplot(total_df, aes(x = xvar, y = yvar, color = df_source))+
    geom_jitter()+
    geom_smooth(method = "lm", se = F)
'''

对我来说,抖动的好处是可以看到每个 df 或“条件”的数据的基本分布。