Skip to content

Simplify sec.axis for proper transformed breaks - #2796

Merged
dpseidel merged 3 commits into
tidyverse:masterfrom
dpseidel:secaxislog
Aug 6, 2018
Merged

dpseidel merged 3 commits into
tidyverse:masterfrom
dpseidel:secaxislog

Conversation

@dpseidel

@dpseidel dpseidel commented Aug 2, 2018

Copy link
Copy Markdown
Collaborator

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

dpseidel commented Aug 2, 2018

Copy link
Copy Markdown
Collaborator Author

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

lock Bot commented Feb 4, 2019

Copy link
Copy Markdown

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