Increase font size of ggplot2 legend

Is there a way to increase the font size in ggplot2 ? I think I need to specify something like legend.key.width = unit(2, "line") in the theme function, but this is used to set up keys in legends, not font sizes. Thank!

+64
r ggplot2
Dec 05 '13 at 18:26
source share
4 answers

You can use theme_get () to display possible variations of the theme. You can control the font size of the legend using:

 + theme(legend.text=element_text(size=X)) 

replacing X with the desired size.

+111
Dec 05 '13 at 18:32
source share
 theme(plot.title = element_text(size = 12, face = "bold") , legend.title=element_text(size=10) , legend.text=element_text(size=9)) 
+10
Nov 01 '16 at
source share

A simpler, but no less effective option:

 + theme_bw(base_size=X) 
+5
Feb 24 '17 at 14:47
source share

You can also specify the font size relative to base_size included in topics such as theme_bw() (where base_size is 11) using the rel() function.

For example:

 ggplot(mtcars, aes(disp, mpg, col=as.factor(cyl))) + geom_point() + theme_bw() + theme(legend.text=element_text(size=rel(0.5))) 
0
Dec 21 '17 at 17:29
source share



All Articles