Skip to content

Simplify sec.axis for proper transformed breaks #2796

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

Merged
merged 3 commits into from
Aug 6, 2018

Conversation

dpseidel
Copy link
Collaborator

@dpseidel dpseidel commented Aug 2, 2018

This PR simplifies the creation of secondary axes to use the transformation of the primary axis when setting breaks and labels rather than relying on an identity transform in all cases. This is a fix for #2729 which was caused by the identity trans calling extended_breaks() by default while the breaks on the primary axis were created by log_breaks() as is default for log-transformed axes.

@thomasp85 As I mentioned this morning, my original fix just used a simple conditional to force log transformed axes to use log_breaks() but after you mentioned the identity trans this morning I decided to take another look at setting the new scale's trans argument by the primary transformation. Ultimately this solves the problem at its source, and is a much more general fix. For instance, dup.axis() should now respect any custom breaks function fed to a custom transformation used on the primary axis. Plus it drastically simplifies the code for building a secondary axis and makes implementation for scale_*_date()/scale_*_datetime() fairly straightforward. In fact I have already implemented sec.axis for these scales on a separate branch and will create a separate PR when this or some iteration of this is merged. Thanks again for making the time this morning, especially given my tardiness.

I've added some new tests, examined numerous plots, and not yet found a case where this breaks anything or significantly changes behavior, but a careful review is warranted.

@dpseidel dpseidel requested a review from thomasp85 August 2, 2018 20:15
@dpseidel
Copy link
Collaborator Author

dpseidel commented Aug 2, 2018

This change also re-fixes #1992, thus #2095 could be effectively reversed, fixing the bug that it introduced into the monotonicity test for some transformed secondary axes. For example, currently this code no longer passes the monotonicity test although it should:

# taken from test-sec-axis
x <- exp(seq(log(0.001), log(1000), length.out = 100))
foo <- data.frame(
  x = x,
  y = x/(1+x)
)

ggplot(foo, aes(x, y)) +
    geom_point() +
    scale_x_sqrt(sec.axis = dup_axis())

I can easily commit changes here fixing this, or in a separate PR after this current PR has been discussed and merged.

@lock
Copy link

lock bot commented Feb 4, 2019

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/

@lock lock bot locked and limited conversation to collaborators Feb 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants