-
Notifications
You must be signed in to change notification settings - Fork 628
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
Translate \n
to <br />
in fct labels, too
#1700
Conversation
Before, this only worked for colums of type character.
Thanks, could you provide some examples of where this is relevant and also write a few tests? |
Sorry for the delay! I finally found some time to meet your requests.
This is relevant whenever you want to plot a data column of type factor with labels containing line breaks. Currently, the line breaks are only translated to HTML ( A very simple example with multiline factor labelslibrary(magrittr)
iris %>%
dplyr::mutate(Species =
Species %>%
forcats::fct_relabel(paste0,
"\n\n(third line)\n(fourth line)")) %>%
plotly::plot_ly(x = ~Sepal.Length,
y = ~Species)
#> No trace type specified:
#> Based on info supplied, a 'bar' trace seems appropriate.
#> Read more about this trace type -> https://plot.ly/r/reference/#bar Created on 2020-04-23 by the reprex package (v0.3.0) The same example when the column is converted to type character before plottinglibrary(magrittr)
iris %>%
dplyr::mutate(Species =
Species %>%
forcats::fct_relabel(paste0,
"\n\n(third line)\n(fourth line)") %>%
as.character()) %>%
plotly::plot_ly(x = ~Sepal.Length,
y = ~Species)
#> No trace type specified:
#> Based on info supplied, a 'bar' trace seems appropriate.
#> Read more about this trace type -> https://plot.ly/r/reference/#bar Created on 2020-04-23 by the reprex package (v0.3.0)
I pushed 841e7e9 which adds an additional test to |
Thanks for the update, this is looking good @salim-b! A couple minor nitpicks:
|
Sorry, I assumed it would be fine to use forcats since it's listed under Regarding
Done :) |
@cpsievert I've added the missing news item in d60898a. I'd be glad if you could merge this PR. 🙂 |
Thank you! |
* Fix bug in verify_attr. Closes issue plotly#1720. * Add test to check that ggplotly does not break discrete x-axis in facet panels with only one category. * Update tests/testthat/test-facet-axis.R Co-authored-by: Carson Sievert <[email protected]> * Add news item. * Translate `\n` to `<br />` in fct labels, too (plotly#1700) * Translate `\n` to `<br />` in fct labels, too Before, this only worked for colums of type character. * add @salim-b as ctb * Add test for `translate_linebreaks()` * remove superfluous char conversion * change order of authors * replace forcats code with base R * add news item Co-authored-by: Stefan Moog <[email protected]> Co-authored-by: Carson Sievert <[email protected]> Co-authored-by: Salim B <[email protected]>
Before, this only worked for colums of type character. This PR adds support for columns of type factor.
The linebreak conversion was first introduced in v4.6.0, see also #851