ggplot2: use scale_colour_brewer() and specify legend name / entry labels manually

被刻印的时光 ゝ 提交于 2019-12-13 05:39:21

问题


I want to use scale_colour_brewer() and scale_fill_brewer() to specify the fill or colours via the brewer palette:

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

Nevertheless, I still want to set the legend label and its entries manually. I did so formerly via:

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

How can I use the auto-palette feature, while still setting the legend name and the entry labels manually?

Thanks!


回答1:


You can use the same arguments name= and labels= also in scale_colour_brewer().

+ scale_colour_brewer(name="Cumulative Percentage", 
                      labels=c("GN","GN1","GN2","GN3","GN4"))


来源:https://stackoverflow.com/questions/23338830/ggplot2-use-scale-colour-brewer-and-specify-legend-name-entry-labels-manual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!