ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

scale_color_stepsn() will not accept expression vector for scale labels

Open palderman opened this issue 1 year ago • 3 comments

An error is generated when attempting to specify color scale labels as a plotmath expression vector. The error is also generated when using scale_fill_stepsn(). I expected the color scale labels to be rendered using plotmath.

Here is code to reproduce the bug:

library(ggplot2)
data.frame(x = 1:5, y = 1:5) |>
  ggplot(aes(x = x, y = y, color = y))+
  geom_text(label = parse(text = paste0("x^", 1:5)))+
  scale_color_stepsn(breaks = 1:5,
                                  colors = c("red", "orange", "yellow","green", "blue"),
                                  labels = parse(text = paste0("x^", 1:5)))
#> Error in `vec_size()`:
#> ! `x` must be a vector, not an expression vector.

Created on 2024-07-17 with reprex v2.1.0

palderman avatar Jul 17 '24 18:07 palderman