get_breaks | R Documentation |
The distances between break-points are always equal in this implementation.
get_breaks(x, n = 10, ...)
## Default S3 method:
get_breaks(x, n = 10, ...)
## S3 method for class 'numeric'
get_breaks(
x,
n = 10,
pretty = TRUE,
expand_min = FALSE,
expand_max = pretty,
...
)
## S3 method for class 'integer64'
get_breaks(x, n = 10, ...)
x |
A numeric vector. |
n |
Number of breakpoints. You may get less or more than requested. |
... |
Extra arguments passed onto methods. |
pretty |
Should pretty break-points be prioritised? Default is |
expand_min |
Should smallest break be extended beyond the
minimum of the data? Default is |
expand_max |
Should largest break be extended beyond the maximum
of the data? Default is |
A numeric vector of break-points.
bin as_discrete
library(cheapr)
set.seed(123)
ages <- sample(0:80, 100, TRUE)
# Pretty
get_breaks(ages, n = 10)
# Not-pretty
# bin-width is diff(range(ages)) / n_breaks
get_breaks(ages, n = 10, pretty = FALSE)
# `get_breaks()` is left-biased in a sense, meaning that
# the first break is always <= `min(x)` but the last break
# may be < `max(x)`
# To get right-biased breaks we can use a helper like so..
right_breaks <- function(x, ...){
-get_breaks(-x, ...)
}
get_breaks(4:24, 10)
right_breaks(4:24, 10)
# Use `rev()` to ensure they are in ascending order
rev(right_breaks(4:24, 10))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.