Is it possible to rename a legend which combines different aesthetics in ggplot2
For example:
- Combine color with linetype: Controlling line color and line type in ggplot legend
- Combine color with shape: How to recycle colours in a colorbrewer palette using line symbols
How could one rename such a combined legend? When I try using name
for scale_shape_manual
or scale_color_manual
the combined legend splits into two different legends. That is not what I want.
Possible Solution: A solution which I found here: https://stackoverflow.com/a/14622513/4317408 worked for me...
Basically there are two possible approaches, in both of them for the combined legend to get a new name, the name
of the two different legends which are combined has to be modified as the same:
scale_color_manual(values = c(brewer.pal(5, "Set1") ) , name = "Combined Legend Title") +
scale_shape_manual(values = c(1,2,3,4,5) , name = "Combined Legend Title")
or
guides(shape=guide_legend(title="Combined Legend Title"), color=guide_legend(title="Combined Legend Title"))
Still I wonder if there is a simpler way of doing this?