-
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
POC: secondary axis functionality in guide_axis()
#5410
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This still needs some more thought around scales that already have non-identity transformations. |
Now works better with transformed scales: devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
library(patchwork)
p <- ggplot(pressure, aes(temperature, pressure)) + geom_line() +
labs(x = "Temperature (\u00b0C)")
p1 <- p + scale_y_log10(sec.axis = sec_axis(sqrt))
p2 <- p + scale_y_log10() + guides(y.sec = guide_axis(trans = sqrt))
p1 | p2 Though it isn't identical w.r.t labels yet. p1 <- p + scale_y_continuous(sec.axis = sec_axis(log10))
p2 <- p + guides(y.sec = guide_axis(trans = log10))
p1 | p2
#> Warning in self$trans(range): NaNs produced
#> Warning in fun(origin_seq): NaNs produced Created on 2023-09-22 with reprex v2.0.2 |
Merged
Merged
Merge branch 'main' into flexible_axis # Conflicts: # R/guide-axis.R
Closing this in favour of #5620 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a proof of concept for putting the functionality of secondary axes in
guide_axis()
.The long term goal may be to lift over responsibilities for secondary axis from the scale system to the guide system.
In this PR,
guide_axis()
gains the argumentsbreaks
,labels
,minor.breaks
andtrans
that would be needed to have secondary axis functionality. This makesguide_axis()
a lot more flexibile, as these arguments can be used to override what the scale passes down. Under the hood, the whole transforming values system gets captured in a new<trans>
with the scales package. Some demos below.This is just to show that it can work similarly to using
sec_axis()
.Because we capture the transformation in a
<trans>
object, we can also provide one directly. There is a little bit of awkwardness in this, as the forwardtransform()
translates secondary data to primary range andinverse()
goes from primary to secondary, which is opposite to the intuition of howtrans
works insec_axis()
.Show that one can override the default breaks and labels:
This PR also makes it possible to have secondary axes for discrete scales with custom labels.
Created on 2023-09-07 with reprex v2.0.2
Currently the minor breaks aren't implemented yet because #5287 provides some extra infrastructure for this.