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: support labelling every nth break #362

Closed
davidhodge931 opened this issue Sep 13, 2022 · 2 comments
Closed

Feature request: support labelling every nth break #362

davidhodge931 opened this issue Sep 13, 2022 · 2 comments

Comments

@davidhodge931
Copy link

davidhodge931 commented Sep 13, 2022

This is particularly useful when facetting. You can do it with a function, but it is complex code, and doesn't seem to integrate with the other scales labelling functions. It'd be be nice as an argument in the label_* functions.

It could look like scales::label_*(..., nth = 1, ...) where 1 would mean label every break, 2 would mean label every second, and 3 every third

library(palmerpenguins)
library(tidyverse)

penguins %>%
  ggplot() +
  geom_jitter(aes(x = sex, y = body_mass_g)) +
  scale_y_continuous(breaks = scales::breaks_pretty(20),
                     labels = \(x) replace(x, seq_along(x)%%2==0, "")) +
  theme_classic()
#> Warning: Removed 2 rows containing missing values (`geom_point()`).

Created on 2023-07-22 with reprex v2.0.2

@davidhodge931 davidhodge931 changed the title Feature request: label_2nd function to label every second break Feature request: support labelling every second break Nov 26, 2022
@davidhodge931 davidhodge931 changed the title Feature request: support labelling every second break Feature request: support labelling every nth break Jul 22, 2023
@davidhodge931
Copy link
Author

label_nth <- function(x, nth = 1) replace(x, seq_along(x)%%nth!=0, "")

@davidhodge931
Copy link
Author

I think this would work better in stringr

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

1 participant