10.6 Changing the Appearance of a Legend Title
10.6.2 Solution
Use theme(legend.title = element_text()
) (Figure 10.11):
ggplot(PlantGrowth, aes(x = group, y = weight, fill = group)) +
pg_plot <- geom_boxplot()
+
pg_plot theme(legend.title = element_text(
face = "italic",
family = "Times",
colour = "red",
size = 14)
)
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:
+
pg_plot guides(fill = guide_legend(title.theme = element_text(
face = "italic",
family = "times",
colour = "red",
size = 14))
)
10.6.4 See Also
See Recipe 9.2 for more on controlling the appearance of text.