This problem was identified in #6287 and affects 8 packages.
Generally, ggplot2 does not accept expressions as aesthetics.
library(ggplot2)
df <- data.frame(x = 1:2, y = 2:3)
ggplot(df, aes(x, y)) +
geom_text(aes(label = expression(foo, bar)))
#> Don't know how to automatically pick scale for object of type <expression>.
#> Defaulting to continuous.
#> Error in `geom_text()`:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `compute_aesthetics()`:
#> ! Aesthetics are not valid data columns.
#> ✖ The following aesthetics are invalid:
#> ✖ `label = expression(foo, bar)`
#> ℹ Did you mistype the name of a data column or forget to add `after_stat()`?
However, with the current CRAN ggplot2, you can circumvent this limitation by passing the label outside the mapping.
ggplot(df, aes(x, y)) +
geom_text(label = expression(foo, bar))
#> Warning in is.na(x): is.na() applied to non-(list or vector) of type
#> 'expression'

In the dev version, we also reject expressions outside the mapping.
devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
ggplot(df, aes(x, y)) +
geom_text(label = expression(foo, bar))
#> Error in `geom_text()`:
#> ! Problem while setting up geom aesthetics.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `list_sizes()` at ggplot2/R/geom-.R:273:3:
#> ! `x$label` must be a vector, not an expression vector.
Created on 2025-01-22 with reprex v2.1.1
Our increased strictness becomes a problem for reverse dependencies. I'm unsure wether ggplot2 should accommodate or the dependencies should follow ggplot2's conventions.
This problem was identified in #6287 and affects 8 packages.
Generally, ggplot2 does not accept expressions as aesthetics.
However, with the current CRAN ggplot2, you can circumvent this limitation by passing the label outside the mapping.
In the dev version, we also reject expressions outside the mapping.
Created on 2025-01-22 with reprex v2.1.1
Our increased strictness becomes a problem for reverse dependencies. I'm unsure wether ggplot2 should accommodate or the dependencies should follow ggplot2's conventions.