在分组条形图上添加图例并更改颜色

Add Legend and change Colour on grouped bar plot

我创建了一个这样的情节;

library("ggplot2")    
ggplot(data = diamonds) + 
      geom_bar(mapping = aes(x = color, y = ..prop.., group = 2)) + 
      scale_y_continuous(labels=scales::percent) +
      facet_grid(~cut)

现在我想为变量 "color" 添加图例,同时我想更改条形图的颜色。该图正是我想要的样子,如果可能的话我不想更改数据集的结构,只需添加图例并更改颜色即可。

我找不到适合这种 "percentage" 风格图形的示例。

ggplot(data = diamonds, aes(x = color, y = ..prop.., group = cut)) + 
  geom_bar(aes(fill = factor(..x.., labels = LETTERS[seq(from = 4, to = 10 )]))) + 
  labs(fill = "color") + 
  scale_y_continuous(labels = scales::percent) + 
  facet_grid(~ cut)