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

sec.axis weird behavior for scale_{x,y}_discrete #6315

Closed
Tiggax opened this issue Jan 30, 2025 · 2 comments
Closed

sec.axis weird behavior for scale_{x,y}_discrete #6315

Tiggax opened this issue Jan 30, 2025 · 2 comments

Comments

@Tiggax
Copy link

Tiggax commented Jan 30, 2025

while trying to create a plot with the help of scale_y_discrete's sec.axis attribute, i am getting weird behavior.

library(ggplot2)
library(stringr)

data <- tibble(
  question = c("A/B", "C/D", "E/F"),
  value = c(.2, .5, .8)
)


data |> 
  ggplot(aes(x = value, y = question)) +
  geom_point() +
  scale_y_discrete(
    labels = \(x) {str_split_i(x,"/",1)},
    name = "A",
    sec.axis = dup_axis(
      labels = \(x) {str_split_i(x,"/",2)},
      name = "B"
    )
  )

I've been trying to create plots for questions favorbility. and tried using the latest main using seeing that #5620 was merged.

The second axis labels do not get the same value provided to scale_y_discrete's labels function.
what instead is passed to the second label is a vector of numbers.

Is this intended behavior?

@teunbrand
Copy link
Collaborator

This issue mirrors #6089 in some ways, but yes: secondary breaks are numeric, so labelling functions will have to deal with this. The reason the breaks are numeric is because that way you're free to place them anywhere instead of just at the primary axis locations.

@teunbrand
Copy link
Collaborator

Closing this as a duplicate of #6089.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants