带有多条回归线的 ggplot 显示随机效应

ggplot with multiple regression lines to show random effects

我知道 this and this 个帖子。但是,当我尝试以下操作时,我似乎没有得到预期的结果:

可以直接从here加载数据。这个想法是,在一个完全虚构的数据集中,几名运动员在完成不同比赛时的血糖水平将取决于一些虚构的氨基酸 (AAA):

剧情要求是:

ggplot(df, aes(x = AAA, y = glucose, color=athletes)) +  
  geom_point() + geom_smooth(method="lm", fill=NA)

而且我希望为每位运动员得到不同的线,而不是一条单一的回归线。我的想法是得到类似于 this.

的东西

是这样的吗?

ggplot(df, aes(x = AAA, y = glucose, color=athletes, group=athletes)) +  
  geom_point() + geom_smooth(method="lm", fill=NA)

或者您可能更喜欢这个

ggplot(df, aes(x = AAA, y = glucose, color=as.factor(athletes), group=as.factor(athletes))) +  
  geom_point() + geom_smooth(method="lm", fill=NA)