wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
650 stars 37 forks source link

Legend keys #112

Open teunbrand opened 6 months ago

teunbrand commented 6 months ago

This PR aims to fix #111.

Briefly, it adds a new function: draw_key_richtext() that can draw legend keys with formatted text. As a demonstration, we can render a similar reprex to the one given in #111:

library(ggplot2) # dev version
devtools::load_all("~/packages/ggtext/")
#> ℹ Loading ggtext

ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
  geom_point(key_glyph = 'richtext') +
  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, label.colour = NA
    ))
  )

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

There are a few questions/remarks I have about how to proceed:

Thanks for reading!

clauswilke commented 6 months ago

I think this can be the default key glyph if it's backwards compatible. I don't know what the status of visual tests is. Haven't looked into it in a long time. I had tons of issues with visual tests (as they would always break with any minor update in the rendering stack), so I've mostly given up on them.

Also, looks like the CI framework is outdated and needs to be fixed before tests pass.