Would it be possible to add arguments to replace newlines with <br> automatically in element_markdown() and geom_richtext()?
Would it be possible to provide a version of scales::label_wrap() that doesn't break markdown syntax?
Would it be possible to vectorize textbox_grob() so that it can be used with theme elements like axis.text.x?
Markdown treats newlines \n as a space character. This creates friction when text data is initially prepared expecting to be working with native ggplot2 functions but then the plot is changed use ggtext functions. The datas to be prepocessed to change any \n to <br>. It also makes it difficult to combine ggtext with scales::label_wrap() to automatically handle line wrapping.
Automatically replacing \n with <br> would help with the first case. Would it be possible to add an argument to element_markdown() and geom_richtext() to facilitate this transformation, either just this substitution (e.g., translate_newline) or a more general argument for transformations to to the text?
For the second case, it's trickier because naively passing a string with markdown syntax to strwrap() could break the markup across lines. One solution would be to provide a version of label_wrap() that applied the breaks after stripping the markup from the text (e.g., label_wrap_markdown()); I'm not sure how feasible that would be. Another option would be for me to switch to element_textbox() and use its built-in line wrapping. This isn't currently possible for axis text because the function textbox_grob() is not vectorized. Would it be possible to vectorize it?
tl;dr:
<br>
automatically inelement_markdown()
andgeom_richtext()
?scales::label_wrap()
that doesn't break markdown syntax?textbox_grob()
so that it can be used with theme elements likeaxis.text.x
?Markdown treats newlines
\n
as a space character. This creates friction when text data is initially prepared expecting to be working with native ggplot2 functions but then the plot is changed use ggtext functions. The datas to be prepocessed to change any\n
to<br>
. It also makes it difficult to combine ggtext withscales::label_wrap()
to automatically handle line wrapping.Automatically replacing
\n
with<br>
would help with the first case. Would it be possible to add an argument toelement_markdown()
andgeom_richtext()
to facilitate this transformation, either just this substitution (e.g.,translate_newline
) or a more general argument for transformations to to the text?For the second case, it's trickier because naively passing a string with markdown syntax to
strwrap()
could break the markup across lines. One solution would be to provide a version oflabel_wrap()
that applied the breaks after stripping the markup from the text (e.g.,label_wrap_markdown()
); I'm not sure how feasible that would be. Another option would be for me to switch toelement_textbox()
and use its built-in line wrapping. This isn't currently possible for axis text because the functiontextbox_grob()
is not vectorized. Would it be possible to vectorize it?