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 / offer: legend keys with markdown formatting #111

Open
teunbrand opened this issue Dec 15, 2023 · 1 comment · May be fixed by #112
Open

Feature request / offer: legend keys with markdown formatting #111

teunbrand opened this issue Dec 15, 2023 · 1 comment · May be fixed by #112

Comments

@teunbrand
Copy link

Hi Claus and Brenton,

I'm interested in using text keys to display the labels of a colour/fill scale.
I think it would be neat if there were a draw_key_markdown() or draw_key_richtext() function to handle formatting of such keys.
For example, in the plot below I'd like the 'Iris' part of the label to be in black, and the species part in the appropriate colour and the whole label in italics.

library(ggplot2) # dev version

ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
  geom_point(key_glyph = 'text') +
  scale_colour_discrete(
    labels = NULL,
    guide = guide_legend(override.aes = list(
      label = paste0(
        "<i><span style='color:black'>Iris</span> ", 
        c("setosa", "versicolor", "virginica"), "</i>"
      ),
      size = 11 / .pt, hjust = 0
    ))
  )

Created on 2023-12-15 with reprex v2.0.2

I'm well aware that there are other options available, such as formatting the scale's labels field, but I'm looking for legend key functions specifically. If this is something that you find appropriate for {ggtext}, I'm reasonably confident I can whip up a PR to consider.

@clauswilke
Copy link
Collaborator

Sure, go ahead. Shouldn't be difficult to write.

@teunbrand teunbrand linked a pull request Dec 15, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants