facet_wrap_labeller: A function to allow for expressions in ggplot facet titles.

Description Usage Arguments Details Value References See Also Examples

Description

Allows for the use of expressions with facet titles.

Usage

1

Arguments

gg.plot

a ggplot object

labels

labels for each facet.

Details

A function to label facetted ggplots

This function alters the lables of a facetted ggplot object. This is useful if you want use expressions or have a simple way to mdify the labels of a facetted ggplot object.

Value

a ggplot object with new facet titles.

References

http://stackoverflow.com/questions/11979017

See Also

plotmath

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Add a factor to the cars example data to facet the plots
library(ggplot2)
x_cars <- data.frame(cars, variable = sample(letters[1:5],
                                             50,
                                             replace = TRUE))
## Create the plot with facets
plt <- ggplot() + geom_point(aes(speed, dist), x_cars) +
       facet_wrap(~variable, ncol=1)
plt
## An example without labels - no real point in this.
library(gridExtra)
facet_wrap_labeller(plt)
## Adding expressions within the facet labels.
facet_wrap_labeller(plt, labels = c(expression(a^2),
                                   expression(b[1]),
                                   expression(frac(c,2)),
                                    "d",
                                     expression(infinity)))

johnDorian/ggsnippets documentation built on May 19, 2019, 3:02 p.m.