Note that an easy way to write a labeller function is to
transform a function operating on character vectors with
as_labeller()
.
A labeller function accepts a data frame of labels (character
vectors) containing one column for each factor. Multiple factors
occur with formula of the type ~first + second
.
The return value must be a rectangular list where each 'row'
characterises a single facet. The list elements can be either
character vectors or lists of plotmath expressions. When multiple
elements are returned, they get displayed on their own new lines
(i.e., each facet gets a multi-line strip of labels).
To illustrate, let's say your labeller returns a list of two
character vectors of length 3. This is a rectangular list because
all elements have the same length. The first facet will get the
first elements of each vector and display each of them on their
own line. Then the second facet gets the second elements of each
vector, and so on.
If it's useful to your labeller, you can retrieve the type
attribute of the incoming data frame of labels. The value of this
attribute reflects the kind of strips your labeller is dealing
with: "cols"
for columns and "rows"
for rows. Note
that facet_wrap()
has columns by default and rows
when the strips are switched with the switch
option. The
facet
attribute also provides metadata on the labels. It
takes the values "grid"
or "wrap"
.
For compatibility with labeller()
, each labeller
function must have the labeller
S3 class.