Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - wrap at a specific character #434

Closed
Moohan opened this issue May 14, 2024 · 1 comment
Closed

Feature - wrap at a specific character #434

Moohan opened this issue May 14, 2024 · 1 comment

Comments

@Moohan
Copy link
Contributor

Moohan commented May 14, 2024

We were discussing label_wrap in a recent training session and it was mentioned that it would be useful to 'wrap at' a specific character, rather than just at a specific width.

I think label_wrap could be expanded to include this behaviour or a new function added e.g.

label_wrap_at <- function(at = "\\s", replace = TRUE) {
  force(at)

  function(x) {
    gsub(glue::glue("({at})"), ifelse(replace, "\n", "\\1\n"), x)
  }
}

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_at())
demo_discrete(x, labels = label_wrap_at("a", replace = FALSE))
demo_discrete(x, labels = label_wrap_at("[aeiou]", replace = FALSE))
demo_discrete(x, labels = label_wrap_at("label", replace = FALSE))

Wrapping at a space is the obvious use case, and it also makes sense to replace the space when doing this, other use cases might be to replace 'at' a given character or word in which case it would make less sense to replace the character.

@thomasp85
Copy link
Member

I have a hard time envisioning how this can be useful in a general sense, since characters can appear wherever in a label and this create very inconvenient wrapping. As such I don't think it is a good fit for scales

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants