increase legend font size ggplot2

RGgplot2

R Problem Overview


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!

R Solutions


Solution 1 - R

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.

Solution 2 - R

theme(plot.title = element_text(size = 12, face = "bold"),
    legend.title=element_text(size=10), 
    legend.text=element_text(size=9))

Solution 3 - R

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() +
  theme(legend.text=element_text(size=rel(0.5)))

Solution 4 - R

A simpler but equally effective option would be:

+ theme_bw(base_size=X)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionalittleboyView Question on Stackoverflow
Solution 1 - RDominic EdwardsView Answer on Stackoverflow
Solution 2 - RAshish MarkandayView Answer on Stackoverflow
Solution 3 - RMegatronView Answer on Stackoverflow
Solution 4 - RJefferson MaiaView Answer on Stackoverflow