I have 2 different lines of code:
ggplot(mpg,aes(displ,hwy,colour = factor(cyl))) + geom_point() + geom_smooth(method = 'lm')
ggplot(mpg,aes(displ,hwy)) + geom_point(aes(colour = factor(cyl))) + geom_smooth(method = 'lm')
The first code produces 3 regression lines for 3 different groups(factor variable) . Second code produces only one line for the whole dataset.
My question is: What is the logic behind this difference? I see, that the output depends on colour = factor(cyl) but can you explain me the logic of ggplo2 in this case?

