Graphics Reference
In-Depth Information
# The base plot
p
<-
ggplot(PlantGrowth, aes(x
=
group, y
=
weight, fill
=
group))
+
geom_boxplot()
# Change the legend label appearance
p
+
theme(legend.text
=
element_text(face
=
"italic"
, family
=
"Times"
, colour
=
"red"
,
size
=
14
))
Figure 10-16. Customized legend label appearance
Discussion
It's also possible to specify the legend label appearance via
guides()
, although this method is a
bit unwieldy. This has the same effect as the previous code:
# Changes the legend title text for the fill legend
p
+
guides(fill
=
guide_legend(label.theme
=
element_text(face
=
"italic"
, family
=
"Times"
, colour
=
"red"
, size
=
14
)))