-
Notifications
You must be signed in to change notification settings - Fork 64
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
Adds text wrapping option to barplot, heatplot, dotplot, & ridgeplot #73
Conversation
It is a neat idea to have this feature. However, there are two concerns:
|
hadley also trying to create a replacement for stringr, see https://github.com/hadley/stringb. After re-think this problem, I think maybe your approach for introducing a new parameter is more user friendly, especially for newbie. But I really don't want to import stringr. HereI write a my_str_wrap <- function(string, width) {
x <- gregexpr(' ', string)
vapply(seq_along(x),
FUN = function(i) {
y <- x[[i]]
n <- nchar(string[i])
len <- (c(y,n) - c(0, y)) ## length + 1
idx <- len > width
j <- which(!idx)
if (length(j) && max(j) == length(len)) {
j <- j[-length(j)]
}
if (length(j)) {
idx[j] <- len[j] + len[j+1] > width
}
idx <- idx[-length(idx)] ## length - 1
start <- c(1, y[idx] + 1)
end <- c(y[idx] - 1, n)
words <- substring(string[i], start, end)
paste0(words, collapse="\n")
},
FUN.VALUE = character(1)
)
}
example: > my_str_wrap(c("abcd efgh xyz bb", "aaaa aa bbcd"), 2)
[1] "abcd\nefgh\nxyz\nbb" "aaaa\naa\nbbcd"
>
>
> stringr::str_wrap(c("abcd efgh xyz bb", "aaaa aa bbcd"), 2)
[1] "abcd\nefgh\nxyz\nbb" "aaaa\naa\nbbcd"
> my_str_wrap(c("abcd efgh xyz bb", "aaaa aa bbcd"), 6)
[1] "abcd\nefgh\nxyz bb" "aaaa\naa\nbbcd"
> stringr::str_wrap(c("abcd efgh xyz bb", "aaaa aa bbcd"), 6)
[1] "abcd\nefgh\nxyz bb" "aaaa\naa\nbbcd"
|
Thank you for looking over my PR.
I also see your point about greater flexibility from providing a user specifiable labeller function. Perhaps we could have the best of both worlds by replacing my |
|
…wrap function, custom labellers
thanks. |
Adds the option
label_wrap_width
which defaults to 30 at the momentThis addresses the issue arrising from long terms for gene sets causing your graphs to be too small or sometimes even competely hidden as a result of very long names.
enrichplot:::barplot.enrichResult(ex, label_wrap_width = 100)
enrichplot:::barplot.enrichResult(ex, label_wrap_width = 20)
NB Underscores are removed from names to allow wrapping