axis_lab {labelr}R Documentation

Retrieve Variable's Name Label for Plot Labeling

Description

axis_lab accepts a data.frame and single unquoted variable name and returns that variable's name label for use in axis labeling or plot labeling function options.

Usage

axis_lab(data, var)

alb(data, var)

Arguments

data

a data.frame.

var

the unquoted name of a variable that exists in the data.frame and is name-labeled (using add_name_labs()).

Details

Note 1: alb is a compact alias for axis_lab: they do the same thing, and the former is easier to type.

Note 2: This command is intended exclusively for interactive use. In particular, the var argument must be the literal name of a single variable (column) found in the supplied data.frame and may NOT be, e.g., the name of a character vector that contains the variable (column name) of interest.

Value

a 1L character vector with var's name label.

Examples

# copy mtcars to df
# create a data set
df <- mtcars

# variable names and their labels
names_labs_vec <- c(
  "mpg" = "Miles/(US) gallon",
  "cyl" = "Number of cylinders",
  "wt" = "Weight (1000 lbs)"
)

df <- add_name_labs(df, name.labs = names_labs_vec)

# ggplot example of axis_lab()
library(ggplot2)
p <- ggplot(df, aes(mpg, wt, color = cyl)) +
  geom_point()
p <- p +
  labs(color = axis_lab(df, cyl)) +
  xlab(axis_lab(df, mpg)) +
  ylab(axis_lab(df, wt))

# Base R plot example (using alb() alias)
with(df, plot(mpg, wt,
  xlab = alb(df, mpg),
  ylab = alb(df, wt)
))


[Package labelr version 0.1.5 Index]