Home > Back-end >  Placing a Legend Title Above a Horizontal Legend Already Positioned at the Top of a Barplot ggplot
Placing a Legend Title Above a Horizontal Legend Already Positioned at the Top of a Barplot ggplot

Time:05-20

Issue:

I have done a lot of research and tried many different solutions and I could not find an answer to my problem, at least not one that worked for me. I am attempting to place the legend title 'Species' above the horizontally placed legend positioned at the top of a barplot (see below) and for it to be centred.

For instance:

enter image description here

CodePudding user response:

If you switch to guides(fill = ...) you should be able do it.

Try:

guides(fill = guide_legend(title.position = "top", title.hjust=0.5)

(thanks to @teunbrand, for minor correction)

  • Related