How can I change the title of a ggplot2 legend?

Add either:

+ scale_fill_discrete(name="Title", labels=c("1","2","3"))

or

+ scale_colour_discrete(name="Title", labels=c("1","2","3"))

depending on the geom.

I recommend you look into the ggplot2 cheatsheet. https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf


Add

+ labs(colour = "legend title") 

to your ggplot call. Great resource site is also google group for ggplot2.

edit: this assumes that colour is the aesthetic in the legend, e.g. qplot(x,y,colour=z). If another aesthetic is being shown in the legend, use that as the argument instead, e.g. + labs(fill = "legend title") for a raster/image plot.

More generally, if you specify an explicit scale such as scale_colour_continuous, you can set the scale_name argument (warning: the details of the arguments to scales may have changed in recent releases of ggplot2; this description is of version 0.9.2.1).


None of the others worked for me for some reason. In case they failed for you as well, adding this worked for me:

+ guides(fill=guide_legend(title='MY NEW TITLE'))

Tags:

R

Ggplot2