Adjust legend box size in ggplot2

In a ggplot graphic how can I make this legend box (in red) wider?

Tough to say without an example to play with. If you need to just make the box wider, add this to your plot:

+ theme(legend.key.width = unit(5, "cm")

Personally, I also find that the width of the line in the legend can be too thin to see the color easily, so I also sometimes add something like this, which overrides the aesthetic mapping only in the legend:

+ guides(colour = guide_legend(override.aes = list(size = 1.2)))
2 Likes

Thank you @EeethB

That solved my problem acurately.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.