You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently saw this tweet, which I thought was a nice suggestion, because it allows you to reuse labels without falling victims to typos and such. It still required a lot of manual management though.
Then, I realised we have several related issues/feature requests already, for example #4631 or #4313. However, I think having a label dictionary is perhaps a more elegant approach than hardcoding a path to retrieve labels from attributes (see also #4631 (comment)).
For the vanilla case, I think it should work something like this:
library(ggplot2)
label_dictionary<- c(
displ="Engine displacement [L]",
hwy="Highway miles per gallon",
"factor(cyl)"="Number of cylinders"# Maybe I should be able to omit the function call?
)
# What I would like to specify
ggplot(mpg, aes(displ, hwy, colour=factor(cyl))) +
geom_point() +
labs(dict=label_dictionary)
# What I would want it to look like
ggplot(mpg, aes(displ, hwy, colour=factor(cyl))) +
geom_point() +
labs(!!!setNames(label_dictionary, c("x", "y", "colour")))
However, for the {Hmisc/tinylabels/labelled/sjlabelled} cases, we might be able to specify dict = derive() (or similar) to specifically instruct to lookup label names in the data.
The text was updated successfully, but these errors were encountered:
@teunbrand This feature will be very useful! It will allow me to not only to simplify the code in 'ggspectra' but, more importantly, easy my plans to implement support for multiple languages.
I'm glad you can see the potential! If you want to give it a spin before it hits the main branch, you can use pak::pak("tidyverse/ggplot2#6077") to install that functionality.
I recently saw this tweet, which I thought was a nice suggestion, because it allows you to reuse labels without falling victims to typos and such. It still required a lot of manual management though.
Then, I realised we have several related issues/feature requests already, for example #4631 or #4313. However, I think having a label dictionary is perhaps a more elegant approach than hardcoding a path to retrieve labels from attributes (see also #4631 (comment)).
For the vanilla case, I think it should work something like this:
Created on 2023-02-05 with reprex v2.0.2
However, for the {Hmisc/tinylabels/labelled/sjlabelled} cases, we might be able to specify
dict = derive()
(or similar) to specifically instruct to lookup label names in the data.The text was updated successfully, but these errors were encountered: