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 request: Convert text to expression for formatting in plot labels. #179

Open
alkaZeltser opened this issue May 10, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@alkaZeltser
Copy link

alkaZeltser commented May 10, 2024

I've noticed several cases where folks want to plot labels formatted in a certain way (in bold, in italics, etc.) where BPG defaults fail to do this automatically. This is particularly annoying when parts of the string are formatted correctly, while others are not. The solutions are to convert text to expressions and manually insert formatting code. Examples of recent discussions: #127 #171

Another recent use-case I've encountered: needing to re-format an entire vector of axis labels. With more than a dozen labels, it is not feasible to manually write out custom expressions to account for each substring. It also required me to learn the entire unintuitive language of expression syntax. Something that could ease this process is a utility function that automatically converts all the characters in a string to expression syntax, e.g. ' ' to ~, inserting * where necessary, and excepting special characters.

For example, I have a vector of labels along the lines of c('red vs. blue', 'red vs. green')
I would like to format the "vs" in italics.
Desired final expression: bold(red~bolditalic(vs\\.)~blue)
Note that the period is a special character.
Next step would be to wrap the expression-ified string in bquote or parse, and pass to e.g. yaxis.lab.

I'm not sure how you could paramaterize inserting unique formatting onto a specific substring, however you could ease the journey by handling all the special expression syntax first. Here is what my imaginary text.to.expression.string would look like:

my.expression.string <- text.to.expression.string('red vs. blue', global.format = bold)
my.expression.string
[1] bold(red~vs\\.~blue)

my.italicized.expression.string <- gsub('vs\\.', 'bolditalic(vs\\.)', my.expression.string)
my.italicized.expression.string
[1] bold(red~bolditalic(vs\\.)~blue)

Can something like text.to.expression.string() be added as a BPG function?

@alkaZeltser alkaZeltser added the enhancement New feature or request label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant