Graphics Reference
In-Depth Information
With
facet_grid()
(but not
facet_wrap()
, at this time), it's possible to use a labeller function
to set the labels. The labeller function
label_both()
will print out both the name of the variable
and the value of the variable in each facet (
Figure 11-5
, left):
ggplot(mpg2, aes(x
=
displ, y
=
hwy))
+
geom_point()
+
facet_grid(drv ~
.
, labeller
=
label_both)
Another useful labeller is
label_parsed()
, which takes strings and treats them as R math ex-
pressions (
Figure 11-5
, right):
mpg3
<-
mpg
levels(mpg3$drv)[levels(mpg3$drv)
==
"4"
]
<-
"4^{wd}"
levels(mpg3$drv)[levels(mpg3$drv)
==
"f"
]
<-
"- Front %.% e^{pi * i}"
levels(mpg3$drv)[levels(mpg3$drv)
==
"r"
]
<-
"4^{wd} - Front"
ggplot(mpg3, aes(x
=
displ, y
=
hwy))
+
geom_point()
+
facet_grid(drv ~
.
, labeller
=
label_parsed)