These labels are the most exact, since they show you whether intervals are "closed" or "open", i.e. whether they include their endpoints.
Arguments
- fmt
String, list or function. A format for break endpoints.
- single
Glue string: label for singleton intervals. See
lbl_glue()
for details. IfNULL
, singleton intervals will be labelled the same way as other intervals.- first
Glue string: override label for the first category. Write e.g.
first = "<{r}"
to create a label like"<18"
. Seelbl_glue()
for details.- last
String: override label for the last category. Write e.g.
last = ">{l}"
to create a label like">65"
. Seelbl_glue()
for details.- raw
. Use the
raw
argument tochop()
instead.
Details
Mathematical set notation looks like this:
[a, b]
: all numbersx
wherea <= x <= b
;(a, b)
: all numbers wherea < x < b
;[a, b)
: all numbers wherea <= x < b
;(a, b]
: all numbers wherea < x <= b
;{a}
: just the numbera
exactly.
Formatting endpoints
If fmt
is not NULL
then it is used to format the endpoints.
If
fmt
is a string, then numeric endpoints will be formatted bysprintf(fmt, breaks)
; other endpoints, e.g. Date objects, will be formatted byformat(breaks, fmt)
.If
fmt
is a list, then it will be used as arguments to format.If
fmt
is a function, it should take a vector of numbers (or other objects that can be used as breaks) and return a character vector. It may be helpful to use functions from the{scales}
package, e.g.scales::label_comma()
.
See also
Other labelling functions:
lbl_dash()
,
lbl_discrete()
,
lbl_endpoints()
,
lbl_glue()
,
lbl_manual()
,
lbl_midpoints()
,
lbl_seq()
Examples
tab(-10:10, c(-3, 0, 0, 3),
labels = lbl_intervals())
#> [-10, -3) [-3, 0) {0} (0, 3) [3, 10]
#> 7 3 1 2 8
tab(-10:10, c(-3, 0, 0, 3),
labels = lbl_intervals(fmt = list(nsmall = 1)))
#> [-10.0, -3.0) [ -3.0, 0.0) { 0.0} ( 0.0, 3.0) [ 3.0, 10.0]
#> 7 3 1 2 8
tab_evenly(runif(20), 10,
labels = lbl_intervals(fmt = percent))
#> [6.095%, 15.1%) [15.1%, 24.11%) [24.11%, 33.11%) [33.11%, 42.12%)
#> 1 2 4 2
#> [42.12%, 51.12%) [51.12%, 60.13%) [60.13%, 69.13%) [78.14%, 87.14%)
#> 2 4 1 2
#> [87.14%, 96.15%]
#> 2