Description Usage Arguments Functions Examples
Truncates, trims, and wraps strings. Built for ggplot2 plots with long string labels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | pretty_string(
x,
truncate_at = 80,
truncate_with = "...",
trim = TRUE,
wrap_at = 40
)
format_pretty_string(
truncate_at = 80,
truncate_with = "...",
trim = TRUE,
wrap_at = 40
)
|
x |
Strings |
truncate_at |
Maximum total string length prior to wrapping. Default is
80 characters. Use |
truncate_with |
Character string that is added at the end of each string
to indicate that the string was truncated. Eats into string length. Default
is |
trim |
Should whitespace be trimmed? Default is |
wrap_at |
Wraps string at given length, passed to |
format_pretty_string
: Provides a pretty string formatter for ggplot2 labels
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | text <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
pretty_string(text, truncate_at = 20, wrap_at = NULL)
pretty_string(text, truncate_at = NULL, wrap_at = 10)
library(ggplot2)
set.seed(654321)
ex <- dplyr::data_frame(
label = sample(stringr::sentences, 3),
value = runif(3, 0, 10)
)
g <- ggplot(ex) +
aes(value, label) +
geom_point()
g
g + scale_y_discrete(
label = format_pretty_string(truncate_at = 25)
)
g + scale_y_discrete(
label = format_pretty_string(truncate_at = NULL, wrap_at = 20)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.