ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

Fix expression labels in `guide_coloursteps()` and `guide_bins()`

Open teunbrand opened this issue 1 year ago • 0 comments

This PR aims to fix #6005.

Briefly, internally we dance around <expression> labels by casting them to lists of expressions when storing them in <data.frame>s and later unpacking such lists to expressions when handing them off to {grid}. I forgot to do this for guide_coloursteps() and guide_bins(), which have very custom code for getting the keys from the scale. This PR rectifies that.

Reprex from the issue:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

p <- data.frame(x = 1:5, y = 1:5) |>
  ggplot(aes(x = x, y = y, color = y))+
  geom_text(label = paste0("x^", 1:5), parse = TRUE)+
  scale_color_stepsn(
    breaks = 1:5,
    colors = c("red", "orange", "yellow","green", "blue"),
    labels = parse(text = paste0("x^", 1:5))
  )
p

p + guides(colour = "bins")

Created on 2024-07-18 with reprex v2.1.1

teunbrand avatar Jul 18 '24 15:07 teunbrand