-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Discrete secondary axes #5620
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
Discrete secondary axes #5620
Conversation
R/axis-secondary.R
Outdated
@@ -130,6 +130,11 @@ is.sec_axis <- function(x) { | |||
|
|||
set_sec_axis <- function(sec.axis, scale) { | |||
if (!is.waive(sec.axis)) { | |||
if (scale$is_discrete()) { | |||
if (!identical(.subset2(sec.axis, "transform"), identity)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .subset2()
prevents wrapping the function into a ggproto method.
Hi, many thanks for implementing this! |
I'm afraid this will not be included in the upcoming release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please add news bullet
Merge branch 'main' into discrete_sec_axis # Conflicts: # R/axis-secondary.R # man/sec_axis.Rd
This PR aims to fix #3171.
Briefly, it adds a
sec.axis
option 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