5

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):

enter image description here

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.

Community
  • 1
  • 1
Antoni Parellada
  • 4,253
  • 6
  • 49
  • 114

1 Answers1

7

something like this?

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

enter image description here

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)

enter image description here

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • Exactly! Let me do something to help change this reputation number you have right now ("666")... :-) I'll accept your answer as soon as the system allows - 8 min. – Antoni Parellada Dec 24 '15 at 15:30
  • BTW. Do you happen to know why it's giving me these confusion blue hues, as opposed to very different colors for each athlete? – Antoni Parellada Dec 24 '15 at 15:31
  • Thank you. Most definitely. I didn't realize until now that you have to wait 8 min before accepting. If I forget to do so, please remind me. – Antoni Parellada Dec 24 '15 at 15:33