-
Notifications
You must be signed in to change notification settings - Fork 2.1k
support sec.axis for scale_discrete #3171
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
Comments
I second this request, and for the same reasons as @maxheld83 mentioned. This would be a really nice feature, which in the current |
Why was this closed? There still seems to be only this workaround available: |
The issue is still open, as far as I can tell. If somebody would like to contribute a PR, we'd certainly review it. It didn't make sense to tackle this feature before @paleolimbot had completed his rewrite of position scales, but since that has happened and is merged I'd assume implementing discrete secondary axes shouldn't be too hard. |
Famous last words! I think a guide extension is the way to go about this (actually, I think regular second axes should use this as well). It's not future proof since we're about to redo guides (post patch release), but you could hack this with the current system: library(ggplot2)
guide_axis_label_trans <- function(label_trans = identity, ...) {
axis_guide <- guide_axis(...)
axis_guide$label_trans <- rlang::as_function(label_trans)
class(axis_guide) <- c("guide_axis_trans", class(axis_guide))
axis_guide
}
guide_train.guide_axis_trans <- function(x, ...) {
trained <- NextMethod()
trained$key$.label <- x$label_trans(trained$key$.label)
trained
}
ggplot(mpg, aes(class, hwy)) +
geom_boxplot() +
guides(x.sec = guide_axis_label_trans(~paste("Ha!", .x))) Created on 2020-04-15 by the reprex package (v0.3.0) |
was searching for something similar and found the SO thread linking to here. |
I also came here from SO looking for a way to duplicate the discrete y scale. +1 this would be a nice feature to see in future versions. Thanks! |
I think it would be nice to have this feature. |
I would like to use Example:
Take care and many thanks |
I have just arrived here from SO. |
I would love this! |
Yes, also a great idea from my perspective! |
I also support this feature request ... even if the xaxis label could just be duplicated without any transformation ... this would be very useful for large / long plots to have the same label on the top and bottom (or left and right, respectively). |
I found this package:
If you run this code you'll see that you can change/customize your secondary axis even with discrete values. |
Joining the others to say this would be nice to have. When you have bipolar questions on surveys, it's nice to put labels on the left and right, just as it appears in the survey itself. |
Agreed! Just here to leave my temporary solutions for others:
|
Agreed! This would be very useful for omics expression heatmaps, where you might want to refer to the accession number as well as the full title of a protein on your plot! +1 |
Seconded. |
Would also like to be able to duplicate categorical axes |
I support this feature request. Thanks! |
Commenting to keep this in favor. |
This works great, but I'm wondering how to modify the following line to use the values of a different variable: I want something like Any guidance would be much appreciated. and a +1 for secondary axes for discrete scales! thanks! |
You should be able to run Worked for my issue. Works great for second y axis too. Glad I found this! Thanks @paleolimbot ! |
I also think it would be nice to move all secondary axis responsibility from the scales system to the guides system, once that has been overhauled. |
Hi, The Is there a plan to integrate this into a ggplot2 official release? Or is it already done and I have missed it? Many thanks! |
Has anyone seen a fix for this when using facets in ggplot? |
Is there a way to add a secondary axis title using the |
Is there any good news about that? It's been 2019, now it's 2023... |
I find another way to build a second axis by package patchwork. you can build a new plot only contain your axis and patch togather. Example for a new x axis in top: p1/p2 + plot_layout(heights = c(0,1)) p2 is your plot need to add axis you also can change axes style as you want (like ggprism) |
scale_y_discrete()
andscale_x_discrete()
currently appear not to support thesec.axis
argument of theirscale_continuous()
brethren.sec.axis
would be nice for discrete scales as well, such as when you have various ways to refer to factor levels (short and long) and the like.The text was updated successfully, but these errors were encountered: