-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sec_axis: minor doc + implementation suggestions #3031
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
Comments
For comment 1, I think you can just write
Does this help? |
Thanks yutannihilation! That's a nice trick for the initiated. I've seen the use of the dot before, but it didn't occur to me I could use it here. Still, |
Thanks. Creating functions with scale_y_continuous(sec.axis = sec_axis(function(y) y / max(y))) I feel |
That would be fantastic. It's easy to read and intuitive. It would make sense to have this particular example listed in the docs too. If |
@thomasp85 @dpseidel |
I'm actually just now working on a big review of the sec.axis framework and the open issues and was going to respond to this in turn. Currently the transformation of the secondary axis is implemented with Lines 142 to 149 in 92d2777
I expect it would take some serious refactoring to accept functions, but I admit I haven't had a chance to look into it yet. |
Basically it just seemed right at the time, and also slightly enforced the use of simple univariate functions which is all that is meaningful for this purpose. Further, anonymous functions as part of ggplot2 calls is pretty uncommon whereas functional notation is at least seen in facets |
Thanks for prompt replies! The reason I asked is because I felt this part can be roughly replaced with building a function beforehand and applying it on data, like: fun <- rlang::as_function(self$trans)
fun(range) (But, I don't have a closer look yet)
OK, I thought we are familiar with using anonymous functions for such arguments as |
You're not incorrect. Both the |
#3038 is a PR to explain what I'm thinking. Please ignore this for now; I'll rethink after your refactoring around secondary axis finished. At the moment, I feel the change is not so significant since it's just about how to store the user's input. |
Great! Yes, my priority right now is trying to refactor |
Thanks. To be clear, I too think formula notation is cleaner and we should promote it. Ultimately, I want to allow both functions and formulas consistently where it's possible, so I expect I'll get urged to make |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
I have used
sec_axis
for the first time and it worked great. Two minor comments below.Comment 1: Functionality suggestion.
Consider:
Suggestion: Allow the scale function to access the variables passed to the
aes()
, so that this become possible:From the end-user perspective,
+ scale_y_secondary(~./max(y))
would be even better.Comment 2: Doc improvement suggestion.
The following is a quote from the docs:
With this wording, I expected to be able to do:
So I would suggest changing "in conjunction with" to "inside a" to make it clear that it's to be used inside. I would also write that it's a function associated with the
sec.axis
argument of the position scale or something to that effect.The text was updated successfully, but these errors were encountered: