"scale_fill_discrete" Not Updating Plot Legend

Hello All,

I am trying to update my plot legend by entering,

scale_fill_discrete(name = "Sex", labels = c("Female", "Male"))

But the legend does not update. Complete code here:

fair_sex <- ggplot(data = Fair, mapping = aes(x = ym, y = nbaffairs, color = sex)) +
  geom_jitter() +
  geom_smooth()
fair_sex <- fair_sex + labs(title = "Number of Affairs by Sex", x = "Number of Affairs", y = "Years Married")
fair_sex <- fair_sex + scale_fill_discrete(name ="Sex", labels c("Female", "Male"))
print(fair_sex)

Any suggestions?

The legend is being made with the color aesthetic so you should change it with scale_color_discrete, I suppose.

2 Likes

When using color in aes, the according scale must be scale_color_discrete.
scale_fill_discrete must be used with the parameter fill in aes.

1 Like

thanks for the awesome information.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.