I was looking here but I can't figure it out.
How can I change the word "type" to something else?
You can use the following syntax to change the legend labels in ggplot2: p + scale_fill_discrete(labels=c('label1', 'label2', 'label3', ...))
In case you need to add a title to the legend, in order to add some description of the elements of the legend, you can use the title argument. Note that you can customize the color of the text with the title. col argument and that you can make a horizontal adjustment of the title with the title. adj argument.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With