ggplot2:使用scale_colour_brewer()并手动指定图例名称/条目标签

时间:2014-04-28 10:36:18

标签: r ggplot2 diagram colorbrewer

我想使用scale_colour_brewer()scale_fill_brewer()通过brewer调色板指定填充或颜色:

diagram <- diagram + scale_colour_brewer() + scale_fill_brewer()

尽管如此,我还是想手动设置图例标签及其条目。我之前通过以下方式这样做了:

diagram + 
  scale_colour_manual(name="Cumulative Percentage", 
  values=c("#d7191c","#fdae61","#000000","#abdda4","#2b83ba"), 
  labels=c("GN","GN1","GN2","GN3","GN4"))

如何手动设置图例名称和条目标签,如何使用自动调色板功能?

谢谢!

1 个答案:

答案 0 :(得分:2)

您也可以在name=

中使用相同的参数labels=scale_colour_brewer().
+ scale_colour_brewer(name="Cumulative Percentage", 
                      labels=c("GN","GN1","GN2","GN3","GN4"))