pretty2: Pretty Breakpoints

Description Usage Arguments Value References Examples

View source: R/pretty2.R

Description

Classic algorithm to create pretty breaks from a numeric vector, see reference. In contrast to base::pretty(), this function works for different number systems and with different notion of "pretty" numbers.

Usage

1
pretty2(x, n = 5, p = c(1, 2, 5), base = 10, tol = 1e-09)

Arguments

x

Numpy array of size >= 2. Used to derive breaks.

n

Approximate number of intervals between breaks. Defaults to 5.

p

List of basic rounding numbers in [1, base), e.g., p = 10/7 will lead to multiples of 1/7, 10/7, 100/7 etc, whatever fits best to x and n. Defaults to c(1, 2, 5).

base

Radix of the number system >= 2. Defaults to 10.

tol

Numeric tolerance for close 0 breaks. Defaults to 1e-9.

Value

A vector with breaks.

References

W. J. Dixon and R. A. Kronmal (1965). The choice of origin and scale for graphs. Journal of the ACM, 12(2):259-261.

Examples

1
2
3
4
5
6
x <- 1:100

pretty2(x)                           # c(0, 20, 40, 60, 80, 100)
pretty2(x, n = 4)                    # c(0, 50, 100, 150)
pretty2(x, base = 5)                 # c(0, 25, 50, 75, 100)
pretty2(x, p = c(10/7, 20/7, 50/7))  # c(0., 28.57143, 57.14286, ...)

mayer79/prettybreaks documentation built on Dec. 21, 2021, 3:53 p.m.