-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Off-label use of plot labels #5
Comments
@teunbrand Hi Teun. Thanks for identifying this issue. I agree that my usage is off-label. It has worked great for years, though I have always suspected it would fail one day. Today is that day! Briefly, the yamlet package allows users to define all their labels in advance, as column attributes on a data.frame having Based on your notes, it looks like I can make good use of the accessor function I will install the development version and revise. Please mention if you think I'm missing something important. |
This should also natively happen in the upcoming ggplot2, so it might pay off to test around a bit to see if this can be skipped
We also made a |
@teunbrand Very helpful, thanks! |
@teunbrand |
That appears to be a misspelling in the examples. The correct argument name is |
@teunbrand Earlier you hinted that the development version of ggplot2 may automatically respect column labels. Indeed, I find it so:
uses the label attribute of
|
Yeah I'm afraid efforts to improve ggplot2 sometimes hurt packages that rely on ggplot2's internal mechanisms. We try to avoid unnecessary breakage, but we cannot always find satisfactory solutions for every dependency (as is the case here).
|
@teunbrand Very helpful, thanks. |
@teunbrand At your convenience, please consider: library(ggplot2)
attr(mtcars$wt, 'label') <- 'Weight (kg)'
a <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
b <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + labs(x = 'Weight (kg)')
identical(get_labs(a), get_labs(b))
#> [1] TRUE
a$labels
#> list()
b$labels
#> $x
#> [1] "Weight (kg)" Created on 2025-02-19 with reprex v2.1.1 Like ggplot2, |
Sounds sensible to me, it is not forbidden to look into internal structures but they are subject to change. |
@teunbrand At |
Hi there,
The ggplot2 package is planning an update for around May 2025 and a reverse dependency test indentified a problem with the yamlet package.
The details are explained in tidyverse/ggplot2#6290, but essentially ggplot2 doesn't populate the
plot$labels
field before plot building anymore.The change in ggplot2 is at odds with how labels are used in the
.decorated_ggplot
function. It appears to me that the plot labels are being used to iterate over aesthetics, but labels are not suitable to derive aesthetics. I think this is off-label use, and would suggest that the yamlet package changes its approach. You can test the changes yourself with the development version of ggplot2 (pak::pak("tidyverse/ggplot2")
)Best,
Teun
The text was updated successfully, but these errors were encountered: