ggplot上geom_point和geom_smooth的不同颜色比例

I am trying to plot observations and their grouped regression lines with ggplot as follows:

ggplot(df, aes(x = cabpol.e, y = pred.vote_share, color = coalshare)) +
  geom_point() +
  scale_color_gradient2(midpoint = 50, low="blue", mid="green", high="red") +
  geom_smooth(aes(x = cabpol.e, y = pred.vote_share, group=coalshare1, fill = coalshare1), se = FALSE, method='lm') +
  scale_fill_manual(values = c(Junior="blue", Medium="green", Senior="red"))

enter image description here The problem is that the lines from geom_smooth are all the same color. I tried using scale_fill_manual so that there aren't two different color scales, and manually determining which color corresponds to each group. but instead all the lines appear blue. How can I make each line a different color?

评论