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 |
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 |
collapse |
logical. If |
... |
Other arguments passed to |
Value
Returns a string vector with wrapped new line characters.
See Also
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)