Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

label_wrap

Label strings by wrapping across multiple lines


Description

Uses strwrap() to split long labels across multiple lines.

Usage

label_wrap(width)

wrap_format(width)

Arguments

width

Number of characters per line.

Value

All label_() functions return a "labelling" function, i.e. a function that takes a vector x and returns a character vector of length(x) giving a label for each input value.

Labelling functions are designed to be used with the labels argument of ggplot2 scales. The examples demonstrate their use with x scales, but they work similarly for all scales, including those that generate legends rather than axes.

Old interface

wrap_format() is retired; please use label_format() instead.

See Also

Other labels for discrete scales: label_parse()

Examples

x <- c(
  "this is a long label",
  "this is another long label",
  "this a label this is even longer"
)
demo_discrete(x)
demo_discrete(x, labels = label_wrap(10))
demo_discrete(x, labels = label_wrap(20))

scales

Scale Functions for Visualization

v1.1.1
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], Dana Seidel [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.