10.6 Changing the Appearance of a Legend Title
10.6.2 Solution
Use theme(legend.title = element_text()
) (Figure 10.11):
pg_plot <- ggplot(PlantGrowth, aes(x = group, y = weight, fill = group)) +
geom_boxplot()
pg_plot +
theme(legend.title = element_text(
face = "italic",
family = "Times",
colour = "red",
size = 14)
)

Figure 10.11: Customized legend title appearance
10.6.3 Discussion
It’s also possible to specify the legend title’s appearance via guides()
, but this method can be a bit verbose. This has the same effect as the previous code:
10.6.4 See Also
See Recipe 9.2 for more on controlling the appearance of text.