You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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.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.
The text was updated successfully, but these errors were encountered: