Reputation: 302
What is the difference in mapping the Species to color aesthetic inside ggplot and inside geom_point. I am using iris data set.
ggplot(aes(x = Sepal.Length, y = Petal.Length, color = Species), data =
trainData)+
geom_point()+
geom_smooth()
AND
ggplot(aes(x = Sepal.Length, y = Petal.Length), data = trainData)+
geom_point(aes(color = Species))+
geom_smooth()
The graph I am getting:
Upvotes: 0
Views: 470
Reputation: 6567
It's probably because the aes() call in the second case colours the points but this is not carried forward to the colour for the smooth line. Changing the second example to add an explicit call to aes(color...) for the geom_smooth() call results in the same result as the first example.
ggplot(aes(x = Sepal.Length, y = Petal.Length), data = trainData) +
geom_point(aes(color = Species)) +
geom_smooth(aes(color=Species))
Upvotes: 1