11.4 Changing the Appearance of Facet Labels and Headers

11.4.1 Problem

You want to change the appearance of facet labels and headers.

11.4.2 Solution

With the theming system, set strip.text to control the text appearance and strip.background to control the background appearance (Figure 11.6):

library(gcookbook)  # Load gcookbook for the cabbage_exp data set

ggplot(cabbage_exp, aes(x = Cultivar, y = Weight)) +
  geom_col() +
  facet_grid(. ~ Date) +
  theme(
    strip.text = element_text(face = "bold", size = rel(1.5)),
    strip.background = element_rect(fill = "lightblue", colour = "black", size = 1)
  )
Customized appearance for facet labels

Figure 11.6: Customized appearance for facet labels

11.4.3 Discussion

Using rel(1.5) makes the label text 1.5 times the size of the base text size for the theme. Using size = 1 for the background makes the outline of the facets 1 mm thick.

11.4.4 See Also

For more on how the theme system works, see Recipes Recipe 9.3 and Recipe 9.4.