5

I am trying to make bar charts using manual fill color. Right now I have the 5 default colors for the 5 columns. I would like to keep using 5 distinct colors but manually specified. I tried the scale_color_manual option but it does not do the job. What am I doing wrong? Thank you.

Example image here

  mycolors <- c("#F8B195", "#F67280", "#C06C84", "#6C5B7B", "#355C7D")
  sub_terms %>% 
    mutate(term=reorder_within(term, beta, topic)) %>% 
    ggplot(aes(term, beta, fill = factor(topic))) +
    geom_col(show.legend = F) +
    scale_color_manual(values=mycolors) +
    facet_wrap(~ topic, scales = "free", nrow=1) +
    coord_flip()+
    scale_x_reordered()
Z.Lin
  • 28,055
  • 6
  • 54
  • 94
clausett
  • 51
  • 1
  • 1
  • 4
  • 3
    `scale_color_manual` will map to the `color` aesthetic whereas you are using `fill` for shading by topic. Use `scale_fill_manual` instead. Note that it would be helpful if you could post a sample of you `sub_terms` data frame to make the question reproducible, see [here](https://stackoverflow.com/q/5963269/3277821). – sboysel Oct 20 '19 at 05:28

1 Answers1

7

As mentioned in a comment to your post, you need to change the scale from color to fill.

Color and fill are distinct different aesthetics, that you can control separately. So when you assign fill you need to scale with scale_fill_manual too.

  mycolors <- c("#F8B195", "#F67280", "#C06C84", "#6C5B7B", "#355C7D")
  sub_terms %>% 
    mutate(term=reorder_within(term, beta, topic)) %>% 
    ggplot(aes(term, beta, fill = factor(topic))) +
    geom_col(show.legend = F) +
    scale_fill_manual(values=mycolors) +
    facet_wrap(~ topic, scales = "free", nrow=1) +
    coord_flip()+
    scale_x_reordered()