ggplot2改变geom_col的填充颜色

cla*_*ett 5 r ggplot2

我正在尝试使用手动填充颜色制作条形图。现在我有 5 列的 5 种默认颜色。我想继续使用 5 种不同的颜色,但手动指定。我尝试了该scale_color_manual选项,但它不起作用。我究竟做错了什么?谢谢。

示例图片在这里

  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()
Run Code Online (Sandbox Code Playgroud)

Ath*_*kel 7

正如您帖子的评论中所提到的,您需要将比例从 更改colorfill

颜色和填充是截然不同的美学,您可以单独控制。因此,当您分配时,fill您也需要进行扩展scale_fill_manual

  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()
Run Code Online (Sandbox Code Playgroud)