-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Description
Problem
If I try to include a lambda in the alt text of labs, the plot will throw an error.
> ggplot2::ggplot(mtcars, ggplot2::aes(x = wt, y = mpg)) +
+ ggplot2::geom_point() +
+ ggplot2::labs(
+ alt = ~ sprintf(
+ "Scatter plot showing %s on x-axis and %s on y-axis",
+ .@labels$x,
+ .@labels$y
+ )
+ )
Error in `.@labels`:
! no applicable method for `@` applied to an object of class "character"
Hide Traceback
▆
1. ├─base (local) `<fn>`(x)
2. └─ggplot2 (local) `print.ggplot2::ggplot`(x)
3. ├─ggplot2::ggplot_build(x)
4. └─ggplot2 (local) `ggplot_build.ggplot2::ggplot`(x)
5. └─ggplot2:::setup_plot_labels(plot, layers, data)
6. └─base::lapply(...)
7. └─ggplot2 (local) FUN(X[[i]], ...)
8. └─global label(labels[[nm]] %||% "")
9. └─base::sprintf(...)However, ggplot2::get_alt_text does work as expected.
> p <- ggplot2::ggplot(mtcars, ggplot2::aes(x = wt, y = mpg)) +
+ ggplot2::geom_point() +
+ ggplot2::labs(
+ alt = ~ sprintf(
+ "Scatter plot showing %s on x-axis and %s on y-axis",
+ .@labels$x,
+ .@labels$y
+ )
+ )
> ggplot2::get_alt_text(p)
[1] "Scatter plot showing wt on x-axis and mpg on y-axis"Solution
I will open a small PR to fix this. I believe the solution is as simple as changing this lapply on line labels.R#L108 to match the call on labels.R#L336
Metadata
Metadata
Assignees
Labels
No labels