Skip to content

Commit

Permalink
Add label_every_nth
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhodge931 committed Nov 22, 2024
1 parent 1fa64ac commit b87d3f7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export(gg_tile)
export(gg_violin)
export(grey)
export(jumble)
export(label_every_nth)
export(light_mode_b)
export(light_mode_r)
export(light_mode_t)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* In `*_mode_*`, updated the legend key size.
* In `*_mode_*`, removed `base_size` scaling of anything other than text size.
* Supported `*_label` to work where a mode is set as a list with `*_label = NULL`.
* Added `label_every_nth`.

# ggblanket 10.0.0

Expand Down
6 changes: 3 additions & 3 deletions R/unexported.R → R/label_every_nth.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#' @description
#' Label every nth element in a vector, and replace the rest with "".
#'
#' @param ... If numeric, arguments passed to the `scales::comma` function. Otherwise, arguments passed to `format`.
#' @param n The increment of elements to hold as is. Defaults to `2`.
#' @param offset An offset for which element to first hold. Defaults to `0`. Possible values are `-1` to (`n - 2`)
#' @param ... If numeric, arguments passed to the `scales::comma` function. Otherwise, arguments passed to `format`.
#'
#' @return A labelling function
#' @noRd
#' @export
#'
#' @examples
#' label_every_nth()(scales::comma(seq(1000, 5000, 1000)))
Expand All @@ -30,7 +30,7 @@
#' y_labels = label_every_nth(),
#' )
#
label_every_nth <- function(n = 2, offset = 0, ...) {
label_every_nth <- function(..., n = 2, offset = 0) {
function(x) {
i <- which(is.finite(x) | is.character(x) | is.factor(x) | is.logical(x))
i <- i[seq_along(i) %% n == (offset + 1)]
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ reference:
- linewidthness
- mode_orientation_to_x
- mode_orientation_to_y

- label_every_nth
41 changes: 41 additions & 0 deletions man/label_every_nth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b87d3f7

Please sign in to comment.