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))
Run the code above in your browser using DataLab