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

Chris picture Chris · Apr 28, 2014 · Viewed 8.3k times · Source

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!

Answer

Didzis Elferts picture Didzis Elferts · Apr 28, 2014

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