rggplot2diagramcolorbrewer

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


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!


Solution

  • 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"))