ggplot with multiple regression lines to show random effects

对着背影说爱祢 提交于 2021-02-07 07:27:19

问题


I am aware of this and this posts. However, I don't seem to get the expected result when I try the following:

The data can be loaded directly from here. The idea is that in a completely made-up data set, the levels of glucose in blood for several athletes at the completion of different races would depend on some fictitious amino acid (AAA):

The call for the plot was:

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

And I expected to get different lines for each one of the athletes, instead of one single regression line. My idea was to get something similar to this.


回答1:


something like this?

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

or maybe you would prefer this

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



来源:https://stackoverflow.com/questions/34454843/ggplot-with-multiple-regression-lines-to-show-random-effects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!