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: hold argument for label_* functions #428

Closed
davidhodge931 opened this issue Apr 30, 2024 · 1 comment
Closed

Feature request: hold argument for label_* functions #428

davidhodge931 opened this issue Apr 30, 2024 · 1 comment

Comments

@davidhodge931
Copy link

davidhodge931 commented Apr 30, 2024

I would like to have flexibility in labelling functions to keep only a subset of the labels.

Some use cases include:

  • colourbars where you only want a range on the guide
  • coloursteps where you want lots of steps, but you don't want a label for each
    etc

In particular, I want to:

  • label only the min/max break
  • label only every second break starting at 1
  • label only every second break starting at 2
    etc

So the other non-kept breaks would need to be returned as "".

An idea to implement this would be as a hold argument in label_* functions that could accept a function.

label_*(hold = \(x) range(x))(1:7) #keep labels in a range
c("1", "", "", "", "", "", "7")

label_*(hold = \(x) x[seq(1, length(x), by = 2))(1:7) #keep every 2nd label starting from the 1st
c("1", "", "3", "", "5", "", "")

label_*(hold = \(x) x[seq(1, length(x), by = 2))(1:7) #keep every 2nd label starting from the 2st
c("1", "", "3", "", "5", "", "7")

label_*(hold = \(x) x[seq(2, length(x), by = 2))(1:7) #keep every 2nd label starting from the 2nd
c("", "2", "", "4", "", "6", "")

label_*(hold = \(x) x[seq(1, length(x), by = 3))(1:7)
c("1", "", "", "4", "", "", "7")
@davidhodge931 davidhodge931 changed the title Feature request: keep argument for label_* functions (or similar) Feature request: keep argument for label_* functions Apr 30, 2024
@davidhodge931 davidhodge931 changed the title Feature request: keep argument for label_* functions Feature request: hold argument for label_* functions May 2, 2024
@davidhodge931
Copy link
Author

Just noticed {purrr} has a function to keep elements, where it is using the word as a synonym for filter.

So prob a different word like hold is better then. Also is kind of like in poker, where the non-held elements could be considered folded as "".

I've created 2 functions that could be used with a hold argument:

  • hold_nth(x, nth = 2, offset = NULL)
  • hold_range(x))

Not sure how you feel about this hold idea? If you like it, and want to implement it, you could also release hold_nth and hold_range functions in {scales}? Otherwise, I'll release my (hacky) functions in {ggblanket} shortly

https://github.com/davidhodge931/ggblanket/blob/main/R/hold.R

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