Skip to content
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 axis labels & breaks arguments work in unexpected ways #6089

Closed
davidhodge931 opened this issue Sep 6, 2024 · 2 comments · Fixed by #6148
Closed

Discrete secondary axis labels & breaks arguments work in unexpected ways #6089

davidhodge931 opened this issue Sep 6, 2024 · 2 comments · Fixed by #6148

Comments

@davidhodge931
Copy link

davidhodge931 commented Sep 6, 2024

I've been testing out the new discrete secondary axis functionality in the DEV version.

Firstly, awesome work and a great advance!

I felt the discrete secondary axis labels and breaks arguments were working in unexpected ways in that:

  1. default sec.axis discrete labels are numeric - should they be the actual labels instead?
  2. palette moves the breaks in scale_*_discrete, but breaks does this in sec.axis - should the sec.axis operate in the same way as the discrete scale?

I'm not familiar with the internals. So there be valid reasons for this that I'm unaware of. Anyway, great work on this. It'll be a super useful feature. Sorry to bombard with issues. As always, feel free to close, if it is working the way you want it to

library(tidyverse)

data <- data.frame(x = c("A", "B", "C"), y = c("D", "E", "F"))

#sec.axis discrete labels are numeric
ggplot(data, aes(x, y)) +
  geom_point() +
  scale_x_discrete(
    sec.axis = dup_axis()
  ) +
  labs(title = "default sec.axis discrete labels are numeric")

#palette moves the breaks in scale_*_discrete but breaks does this in sec.axis
ggplot(data, aes(x, y)) +
  geom_point() +
  scale_x_discrete(
    palette = \(x) c(0.5, 1.5, 3.5),
    sec.axis = dup_axis(
      breaks = c(1.3, 3, 4)
    )
  ) +
  labs(title = "palette moves the breaks in scale_*_discrete but breaks does in sec.axis")

Created on 2024-09-07 with reprex v2.1.1

@davidhodge931 davidhodge931 changed the title Discrete secondary axis labels and breaks arguments working in unexpected ways Discrete secondary axis labels and breaks arguments work in unexpected ways Sep 6, 2024
@davidhodge931 davidhodge931 changed the title Discrete secondary axis labels and breaks arguments work in unexpected ways Discrete secondary axis labels & breaks arguments work in unexpected ways Sep 6, 2024
@teunbrand
Copy link
Collaborator

I guess the think to grok is that secondary discrete axes operate on the numeric equivalent of the discrete scale. Hanging onto the constraints of discrete scales makes secondary discrete axes clunky to use.

default sec.axis discrete labels are numeric - should they be the actual labels instead?

This would only makes sense if the secondary breaks positions match the primary ones, which isn't guaranteed. Besides that, we kind of assumed that people'd use secondary axes to display something else than the primary axis labels.

palette moves the breaks in scale_*_discrete, but breaks does this in sec.axis - should the sec.axis operate in the same way as the discrete scale?

I really don't like the idea of the primary and secondary axes having different palettes.

@davidhodge931
Copy link
Author

I suppose my point is from a user's perspective, you expect a discrete secondary axis to duplicate the discrete primary axis - and therefore the same arguments to work in the same way

teunbrand added a commit to teunbrand/ggplot2 that referenced this issue Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants