Reputation: 665
I have a rather simple issue in ggplot2 I am not being able to solve.
I have the following dataframe:
date country party value
<dbl> <chr> <chr> <dbl>
2019 UK Conservatives 15
2019 UK Labour 16
2019 UK Lib Dem 12
2019 UK Greens 31
2020 UK Conservatives 13
2020 UK Labour 14
2020 UK Lib Dem 12
2020 UK Greens 32
And I want to plot but assign specific colours to different values of party
.
I've tried it this way:
p <- df%>%
ggplot( aes(x=as.factor(date), y=value, fill=party)) +
geom_bar(stat="identity", position=position_dodge())+
geom_text(aes(label=value), vjust=1.6, color="white",
position = position_dodge(0.9), size=3.5)+
theme_minimal()
and then:
p + scale_colour_manual(values = c("Conservatives" = "cyan",
"Greens" = "chartreuse3",
"Labour" = "brown3",
"Lib Dems" = "darkgoldenrod1")) #these are the colours I want to assign each level of `party`.
But as you can see instead of actually printing out the colours I select, I still get the same colours as if I just called p
.
Any idea why? Thanks!
Upvotes: 0
Views: 1619
Reputation: 400
Try scale_fill_manual
instead of scale_colour_manual
:
p + scale_fill_manual(values = c("cyan", "chartreuse3", "brown3", "darkgoldenrod1"))
Upvotes: 3