I'm trying to create a smooth plot in which color represents manufacturer
and the lines represent the overall relationship between disp
and hwy
. I can do that with this:
df <- subset(mpg, manufacturer==c("audi","chevrolet"))
df$year <- factor(df$year)
ggplot(df, aes(displ, hwy, color = manufacturer)) +
geom_smooth(se = FALSE, method = lm)
Now I would like df$year
to be plotted with the same colors for audi
and chevrolet
in the plot above. So two (1998
and 2009
) redish lines for audi
and two (1998
and 2009
) blueish lines for chevrolet
.
I tried adding this line to the command above
+ geom_smooth(aes(color=year), se = FALSE, method = lm)
but it creates a separate legend for year
with different colors, whereas I want the lines to match the audi
and chevrolet
colors from the plot above