f_wrap {numform}R Documentation

Wrap Strings

Description

Wrap strings by splitting n width, and paste collapsing with new line characters.

Usage

f_wrap(
  x,
  width = 15,
  sep = "\n",
  exdent = 0,
  indent = 0,
  equal.lines = FALSE,
  collapse = FALSE,
  ...
)

ff_wrap(...)

Arguments

x

A vector of text strings.

width

A positive integer giving the target column for wrapping lines in the output.

sep

A new line separator (defaults to "\n".

exdent

A non-negative integer specifying the indentation of subsequent lines in paragraphs.

indent

A non-negative integer giving the indentation of the first line in a paragraph.

equal.lines

logical. If TRUE the number of lines for each element will be made the same by appending additional '\n' to those below the max number of lines. This is useful for legend spacing.

collapse

logical. If TRUE then x is collapsed via paste(x, collapse = ' ') before processing. This is useful for muti-line text wrapping of longer subtitles.

...

Other arguments passed to strwrap.

Value

Returns a string vector with wrapped new line characters.

See Also

strwrap

Examples

cat(f_wrap('really long label names are the pits'))
cat(f_wrap('really long label names are the pits', width = 20, exdent = 2))
f_wrap(c('really long label names are the pits and make us sad',
    'not nearly so long'), equal.lines = TRUE)

## Not run: 
library(tidyverse); library(gridExtra)

set.seed(10)
dat <- data_frame(
    level = c('Not Involved', 'Somewhat Involved Single Group',
        'Somewhat Involved Multiple Groups', 'Very Involved One Group',
        'Very Involved Multiple Groups'
    ),
    n = sample(1:10, length(level))
) %>%
    mutate(
        level = factor(level, levels = unique(level)),
        `%` = n/sum(n)
    )

gridExtra::grid.arrange(
    dat %>%
        ggplot(aes(level, `%`)) +
            geom_col() +
            labs(title = 'Yucky Labels', y = NULL),

    dat %>%
        ggplot(aes(level, `%`)) +
            geom_col() +
            scale_x_discrete(labels = f_wrap) +
            scale_y_continuous(labels = ff_prop2percent(digits = 0)) +
            labs(title = 'Happy Labels', y = NULL),

    ncol = 1, heights = c(.45, .55)
)


## End(Not run)

[Package numform version 0.7.0 Index]