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

Feature request: label_number() can prepend '≤' and '≥' symbols #368

Closed
teunbrand opened this issue Nov 5, 2022 · 1 comment
Closed

Comments

@teunbrand
Copy link
Contributor

When plotting a scale with squished oob-handling, I often find it clearer to indicate this with the ≤ and ≥ symbols prepended to the first and last labels respectively. Currently, this requires manually setting breaks and labels.

library(ggplot2)
library(scales)

ggplot(faithful, aes(waiting, eruptions)) +
  geom_point() +
  scale_y_continuous(
    limits = c(2, 4),
    breaks = c(2, 2.5, 3, 3.5, 4),
    labels = c("≤2.0", "2.5", "3.0", "3.5", "≥4.0"),
    oob = oob_squish
  )

Created on 2022-11-05 by the reprex package (v2.0.1)

I think it would be great if this could be an option in the label_number() function, for example with a squished argument taking a logical vector for the lower and upper limit respectively.

ggplot(faithful, aes(waiting, eruptions)) +
  geom_point() +
  scale_y_continuous(
    limits = c(2, 4),
    labels = scales::label_number(squished = c(TRUE, TRUE)),
    oob = oob_squish
  )
@thomasp85
Copy link
Member

I don't think this sort of special behaviour fits into scales. It is pretty easy to wrap label_number() in a function that prepends this to the output if you need it often

ggplot(faithful, aes(waiting, eruptions)) +
    geom_point() +
    scale_y_continuous(
        limits = c(2, 4),
        labels = \(...) {l <- scales::label_number()(...); l[c(1, length(l))] <- paste0(c("",""), l[c(1, length(l))]); l},
        oob = oob_squish
    )

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