-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Allow scale name to be a function. #4313
Comments
I like the idea. One more thing to consider is how to handle Lines 515 to 517 in 37eb64d
|
I saw that but didn't know what it did, so I didn't dare to touch anything. Is that for the second axis, if there is one? |
On this topic: For any new function you add, or any related existing function where you figure out what it does, please add a few comments to the code in |
Yes, I guess so, but I too don't know well about the Scale-related things. Honestly, I have no idea what is the case when there's no Lines 144 to 150 in 37eb64d
The mechanism was added by #1868, so we might find some clue there. |
Well, maybe @thomasp85 remembers what he did there. :-) |
I think I got it. I need to add a similar trick here: Lines 122 to 129 in 37eb64d
With that change, now it works also for secondary axis. library(ggplot2)
df <- expand.grid(X1 = 1:10, X2 = 1:10)
df$value <- df$X1 * df$X2
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p1 + scale_x_continuous(~ base::tolower(.x),
sec.axis = sec_axis(trans = identity,
name = ~ gsub("x", "xx", .x))) +
scale_fill_continuous(~ base::toupper(.x)) Created on 2021-01-11 by the reprex package (v0.3.0) How should I test this new functionality? My default idea is to create visual tests, but there must be a more specific way. |
@clauswilke you think too highly of my memory 😄 But I'm sure I had my reasons... |
@eliocamp are you in the process of preparing a PR? |
and do your changes also work with |
It doesn't, and for it to fully work I'd need to change a lot of how Right now Lines 13 to 17 in de0b9e3
However, if library(ggplot2)
df <- expand.grid(X1 = 1:10, X2 = 1:10)
df$lowercase <- df$X1 * df$X2
ggplot(df, aes(X1, X2)) +
geom_tile(aes(fill = lowercase)) +
labs(fill = ~base::toupper(.x)) ggplot(df, aes(X1, X2)) +
labs(fill = ~base::toupper(.x)) +
geom_tile(aes(fill = lowercase)) Created on 2021-03-24 by the reprex package (v1.0.0) To solve this |
I would hold off on touching |
Any advice on how to add tests for this feature? Should it be a visual test or there's a better way of checking the text of axis and legends? |
Any implementation of this could include a fix for #4631 Sounds like we could ignore @eliocamp I think you should be able to find some part of the data structure that exposes the actual name and test that. I don't remember where it is, but if I was writing the test, I would start by doing a |
I think it might be useful to have the possibility of passing a function to scale names like so:
Created on 2021-01-11 by the reprex package (v0.3.0)
Something like this would make code snippets more portable. In my case, I have a function that makes a plot and I had to define the title outside the plot depending on the function arguments. With this, I could've defined a global dictionary which translates column names to actual (human readable) variable names and re-use that all over my report.
To produce the code above I just added this
before this line:
https://github.com/tidyverse/ggplot2/blob/master/R/scale-.r#L107
And then added
make_title = make_title
to the ggproto construction.All tests pass, so changing this should be safe.
The text was updated successfully, but these errors were encountered: