0

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`. 

Plot I get out

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!

1 Answer 1

3

Try scale_fill_manual instead of scale_colour_manual:

p + scale_fill_manual(values = c("cyan", "chartreuse3", "brown3", "darkgoldenrod1")) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.