chop_pretty() uses base::pretty() to calculate breakpoints
which are 1, 2 or 5 times a power of 10. These look nice in graphs.
Arguments
- x
A vector.
- n
Positive integer passed to
base::pretty(). How many intervals to chop into?- ...
Passed to
chop()bychop_pretty()andtab_pretty(); passed tobase::pretty()bybrk_pretty().
Value
chop_* functions return a factor of the same length as x.
brk_* functions return a function to create breaks.
tab_* functions return a contingency table().
Details
base::pretty() tries to return n+1 breakpoints, i.e. n intervals, but
note that this is not guaranteed. There are methods for Date and POSIXct
objects.
For fine-grained control over base::pretty() parameters, use
chop(x, brk_pretty(...)).
Examples
chop_pretty(1:10)
#> [1] [0, 2) [2, 4) [2, 4) [4, 6) [4, 6) [6, 8) [6, 8) [8, 10] [8, 10]
#> [10] [8, 10]
#> Levels: [0, 2) [2, 4) [4, 6) [6, 8) [8, 10]
chop(1:10, brk_pretty(n = 5, high.u.bias = 0))
#> [1] [1, 2) [2, 3) [3, 4) [4, 5) [5, 6) [6, 7) [7, 8) [8, 9) [9, 10]
#> [10] [9, 10]
#> Levels: [1, 2) [2, 3) [3, 4) [4, 5) [5, 6) [6, 7) [7, 8) [8, 9) [9, 10]
tab_pretty(1:10)
#> [0, 2) [2, 4) [4, 6) [6, 8) [8, 10]
#> 1 2 2 2 3
