Closed teunbrand closed 5 months ago
I really like this! With the newest support for the label attribute in RStudio, I am taking even more advantage of it. would be great if ggplot2 used it too! gt also does this by default
Closing this in favour of #5879
This PR aims to fix #4631 and it competes with #5879.
Briefly, an attempt is made to derive default labels from the 'label' attribute.
Less brief,
make_labels()
now accepts adata
argument. When there are simple symbolic mappings, these are evaluated and searched for a label attribute. There are some limitations with this approach that are detailed below.To give an example we can give the
mtcars
dataset some label attributes. Notice in the plot below that all default labels are derived from the attribute, regarless of whether it comes from the global mapping, the layer mapping or data pronoun use.When we use a standalone
+ aes(...)
it also yields the exact same plot.As for the limitations, here are some that I noticed. When using layer data, global aesthetics do not get searched.
Also, when the data is a function, the labels cannot be retrieved. The data also isn't
fortify()
'ed or in any way preprocessed.Created on 2024-05-02 with reprex v2.1.0
The labels are also baked in at the time the layers are added, so doing the following:
Does not give the attribute labels.
These limitations could be resolved if the labels were derived in the
ggplot_build()
step, but as that function is somewhat sacred, I tried this approach first. Also, as this does not have an on/off switch, this PR will break some plots (but hopefully for the better).Despite these limitations, I think this is an improvement over the current situation. See #5879 for a second option with fewer limitations.