Skip to content

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

Closed
@davidhodge931

Description

@davidhodge931

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions