
Get labels for each observation according to bin cuts in the histogram.
Source:R/l_binCut.R
l_binCut.Rd
l_binCut
divides l_hist
widget x
into current histogram intervals and codes values
x
according to which interval they fall (if active). It is modelled on cut
in base
package.
Arguments
- widget
A loon histogram widget.
- labels
Labels to identify which bin observations are in. By default, labels are constructed using "(a,b]" interval notation. If
labels = FALSE
, simple integer codes given by the histogram's bin number are returned instead of a factor. Thelabels
can also be any vector of length equal to the number of bins; these will be used to construct a vector identifying the bins.- digits
The number of digits used in formatting the breaks for default labels.
- inactive
The value to use for inactive observations when labels is a vector. Default depends on
labels
.
Value
A vector of bin identifiers having length equal to the total number of observations in the histogram.
The type of vector depends on the labels
argument.
For default labels = NULL
, a factor is returned, for labels = FALSE
, a vector of bin numbers, and
for arbitrary vector labels
a vector of bins labelled in order of labels
will be returned.
Inactive cases appear in no bin and so are assigned the value of active
when given.
The default active
value also depends on labels
: when labels = NULL
, the default active
is "(-Inf, Inf)"
;
when labels = FALSE
, the default active
is -1
; and when labels
is a vector of length equal
to the number of bins, the default active
is NA
.
The value of active
denotes the bin name for the inactive cases.
Examples
if(interactive()) {
h <- l_hist(iris)
h["active"] <- iris$Species != "setosa"
binCut <- l_binCut(h)
h['color'] <- binCut
## number of bins
nBins <- length(l_getBinIds(h))
## ggplot color hue
gg_color_hue <- function(n) {
hues <- seq(15, 375, length = n + 1)
hcl(h = hues, l = 65, c = 100)[1:n]
}
h['color'] <- l_binCut(h, labels = gg_color_hue(nBins), inactive = "firebrick")
h["active"] <- TRUE
}