Graphics Reference
In-Depth Information
Changing the Appearance of Facet Labels and
Headers
Problem
You want to change the appearance of facet labels and headers.
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)
# For the data set
ggplot(cabbage_exp, aes(x
=
Cultivar, y
=
Weight))
+
geom_bar(stat
=
"identity"
)
+
facet_grid(
.
~ Date)
+
theme(strip.text
=
element_text(face
=
"bold"
, size
=
rel(
1.5
)),
strip.background
=
element_rect(fill
=
"lightblue"
, colour
=
"black"
,
size
=
1
))
Figure 11-6. Customized appearance for facet labels
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.