Repository navigation
Discrete secondary axes - #5620
Merged
Merged
Conversation
teunbrand
commented
Jan 2, 2024
| set_sec_axis <- function(sec.axis, scale) { | ||
| if (!is.waive(sec.axis)) { | ||
| if (scale$is_discrete()) { | ||
| if (!identical(.subset2(sec.axis, "transform"), identity)) { |
Collaborator
Author
There was a problem hiding this comment.
The .subset2() prevents wrapping the function into a ggproto method.
Contributor
|
Hi, many thanks for implementing this! |
Collaborator
Author
|
I'm afraid this will not be included in the upcoming release. |
thomasp85
approved these changes
May 16, 2024
thomasp85
left a comment
Member
There was a problem hiding this comment.
LGTM. Please add news bullet
Merge branch 'main' into discrete_sec_axis # Conflicts: # R/axis-secondary.R # man/sec_axis.Rd
This file contains hidden or 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
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 aims to fix #3171.
Briefly, it adds a
sec.axisoption forscale_{x/y}_discrete().For context:
The secondary axis system is not ideal. We have tried to move that functionality to guides in #5410, but it becomes too complicated. Because it doesn't seem viable to handle this functionality in guides, I think it is time to implement secondary axes for discrete scales.
In some more detail:
It currently only accepts identity transformations, as it just doesn't make sense to me why one would transform a discrete axis.
This also means that
dup_axis()should be preferred tosec_axis()for discrete scales.Breaks can be given as numeric that can take arbitrary positions, or as discrete breaks that can take one of the limits values.
For discrete scales, breaks are mapped early on in
AxisSecondary$break_info().An example plot with relabelling the x-axis and numeric positions in the y-axis:
Created on 2024-01-02 with reprex v2.0.2