Description Usage Arguments Examples
Allows every nth
element of a vector x
to either be (1)
replaced with an empty character placeholder (empty = TRUE
;
default) or (2) omitted from the vector (empty = FALSE
).
Additionally, it provides the option of requesting the inverse
(inverse = TRUE
; not default) of the vector and associated
empty or omitted elements. See examples.
1 |
x |
numeric vector |
nth |
numeric scalar indicating which elements of |
empty |
logical; replace |
inverse |
logical; return the inverse of |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | numvec <- 0:20
charvec <- LETTERS
## Replace every 3rd element with an empty character
every_nth(numvec, 3) # conversion to character vector
every_nth(charvec, 3)
## Omit (drop) every 3rd element
every_nth(numvec, 3, empty = FALSE) # vector mode is preserved
every_nth(charvec, 3, empty = FALSE)
## For creation of minor ticks, return the inverse
## Retain every 3rd element, replacing all others with empty character
every_nth(numvec, 3, inverse = TRUE) # conversion to character vector
every_nth(charvec, 3, inverse = TRUE)
## Retain every 3rd element, omitting (dropping) all other elements
every_nth(numvec, 3, empty = FALSE, inverse = TRUE) # vector mode is preserved
every_nth(charvec, 3, empty = FALSE, inverse = TRUE)
## Not run:
library(ggplot2)
df <- data.frame(x = rnorm(1000), y = rnorm(1000))
## default axis labelling
p <- ggplot(df, aes(x, y)) + geom_point() + theme_bw()
p
## Add minor ticks to axes
custom_breaks <- seq(-3, 3, 0.25)
p +
scale_x_continuous(breaks = custom_breaks,
labels = every_nth(custom_breaks, 4, inverse = TRUE)) +
scale_y_continuous(breaks = custom_breaks,
labels = every_nth(custom_breaks, 2, inverse = TRUE))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.