[Solved] increase legend font size ggplot2

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 that is used to adjust the keys in legends, not the font sizes. Thanks!

Solution #1:

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

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

replacing X with the desired size.

Respondent: Dominic Edwards

Solution #2:

theme(plot.title = element_text(size = 12, face = "bold"),
Respondent: Ashish Markanday

Solution #3:

You can also specify the font size relative to the base_size included in themes 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() +
Respondent: Megatron

Solution #4:

A simpler but equally effective option would be:

+ theme_bw(base_size=X)
Respondent: Jefferson Maia

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.