Learn R Programming

cheapr (version 0.9.8)

get_breaks: Pretty break-points for continuous (numeric) data

Description

The distances between break-points are always equal in this implementation.

Usage

get_breaks(x, n = 7, ...)

# S3 method for numeric get_breaks( x, n = 7, pretty = TRUE, expand_min = FALSE, expand_max = FALSE, ... )

# S3 method for integer64 get_breaks(x, n = 7, ...)

Value

A numeric vector of break-points.

Arguments

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 TRUE.

expand_min

Should smallest break be extended beyond the minimum of the data? Default is FALSE.

expand_max

Should largest break be extended beyond the maximum of the data? Default is FALSE.

Examples

Run this code
library(cheapr)

set.seed(123)
ages <- sample(0:80, 100, TRUE)

get_breaks(ages, n = 10)

## To get the same break-points that `cut()` produces, we can do this..

signif(
  get_breaks(ages, n = 5, pretty = FALSE,
             expand_min = TRUE, expand_max = TRUE), 3
)
levels(cut(ages, 5))

Run the code above in your browser using DataLab