ggplot2 changing fill colors of geom_col

Viewed 7827

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()
1 Answers

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()
Related