Skip to content

Conversation

yutannihilation
Copy link
Member

Fix #6638

Quote myself in #6622 (comment):

The error happens here. key is a data frame containing a latexexpression object in .label column.

key <- vec_slice(key, is.finite(oob_censor_any(breaks, range)))

The problem is, the latexexpression object cannot be subset by vec_slice() because

x <- as.list(latex2exp::TeX("$\\alpha$"))
vctrs::obj_is_vector(x)
#> [1] FALSE

However, it works if the object doesn't have S3 classes.

vctrs::obj_is_vector(unclass(x))
#> [1] TRUE

This pull request fixes the error by simply removing the class. Honestly, I'm not fully sure if this doesn't break any existing usage that actually requires the class information in labels. But, I believe this does the right thing.


devtools::load_all("~/GitHub/ggplot2/")
#> ℹ Loading ggplot2
#> Overwriting method +(<ggplot2::ggplot>, <ANY>)
#> 
#> Overwriting method +(<ggplot2::theme>, <ANY>)
#> 
#> Overwriting method convert(<ggplot2::ggplot>, <list>)
library(latex2exp)
ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  scale_x_continuous(breaks = 3, labels = TeX("$\\alpha$"))

Created on 2025-09-24 with reprex v2.1.1

@yutannihilation yutannihilation deleted the fix/issue-6638-classed-expression-labels branch September 24, 2025 15:46
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 this pull request may close these issues.

expressions as tick label broken
1 participant