labeller: ggplot2 labeller

Description Usage Arguments Examples

View source: R/labeller.R

Description

This function works as a labelling mapper for ggplot2, typically used in facet_grid. All arguments must be named. Items are mapped as name => value, where name represents the original levels of the factor used for facetting.

Usage

1
labeller(..., .parse = TRUE)

Arguments

...

A set of named arguments.

.parse

boolean; if TRUE we parse the text as though it were an expression.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
if (require(ggplot2)) {

  df <- data.frame(
    x=1:100,
    y=rnorm(100),
    grp=rep( c("tau+", "tau-"), each=50 ) ## levels are "tau+", "tau-"
  )

  f <- labeller(
    `tau-` = 'tau["-"]',
    `tau+` = 'tau["+"]'
  )

  ggplot(df, aes(x=x, y=y)) +
    geom_point() +
    facet_grid(". ~ grp", labeller=f)

  df$grp2 <- factor(rep( c("beta+", "beta-"), each=50 ))

  f <- labeller(
    `tau-` = 'tau["-"]',
    `tau+` = 'tau["+"]',
    `beta+` = 'beta["+"]',
    `beta-` = 'beta["-"]'
  )

  ggplot(df, aes(x=x, y=y)) +
    geom_point() +
    facet_grid("grp ~ grp2", labeller=f)
}

Kmisc documentation built on May 29, 2017, 1:43 p.m.

Related to labeller in Kmisc...