Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to fix #5178.
Briefly, it adds
labs(dict)
that allows one to use a data-dictionary to label a plot based on variable names (rather than aesthetics).Let's just jump into examples.
The premise of this idea is that somewhere in your analysis code, you have some nice labels about what variables in your dataset mean. For example, we could have the following for the
mpg
dataset.This PR lets you slap on such a dictionary to your labels, and all variable names will be translated. The benefit is that you only have to think about pretty lables for variables once and you needn't worry about them again.
Noteably, this doesn't work when having more complex expressions, like
factor(cyl)
instead ofcyl
. In such case, you can fall back to labelling the aesthetic, or you can add an entry likelabs(dict = c(dict,
factor(cyl)= dict[["cyl"]]))
. Also we can reuse the dictionary here because we're using the same dataset even though we're making a totally different plot.Created on 2024-09-04 with reprex v2.1.1