A discretizing scale by sample quantiles: each range element stands for an equal share of the samples (spec/06 ยง11).
scale = Macaw.Draw.Scale.Quantile.new() |> Macaw.Draw.Scale.Quantile.domain!([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100])
scale = Macaw.Draw.Scale.Quantile.range(scale, ["Q1", "Q2", "Q3", "Q4"])
Macaw.Draw.Scale.Quantile.quantiles(scale)
#=> [3.5, 6.0, 8.5]The thresholds are derived, never set: the i/n quantiles of the sorted samples by
linear interpolation, for n the range's length. apply/2 answers the range element at
the count of thresholds at or below the value, nil for a value that is no number.
Summary
Functions
The range element of the value's bucket: the count of thresholds at or below it.
nil for an empty range or a value that is no number; the first element when there
are no thresholds.
0: a quantile scale has no bandwidth.
Identity: a quantile scale always maps into its range.
Sets the samples, numbers, sorted on entry: {:ok, scale}, or {:error, faults} with
{[i], {:type, :number}} for an element that is not one.
domain/2, answering the scale or raising Macaw.Draw.Error.
nil: a quantile scale maps many values to one bucket.
The samples' extent of the bucket a range element stands for, {lo, hi}: the first
sample or the threshold below, the last sample or the threshold above. nil for an
empty domain or range, or an element not in the range.
A quantile scale with no samples and no range.
Identity.
Identity: a quantile scale has no padding.
The n โ 1 interior quantiles, the thresholds.
Sets the range, a list; answers the struct.
quantiles/1; the count is ignored.
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
Functions
The range element of the value's bucket: the count of thresholds at or below it.
nil for an empty range or a value that is no number; the first element when there
are no thresholds.
0: a quantile scale has no bandwidth.
Identity: a quantile scale always maps into its range.
Sets the samples, numbers, sorted on entry: {:ok, scale}, or {:error, faults} with
{[i], {:type, :number}} for an element that is not one.
domain/2, answering the scale or raising Macaw.Draw.Error.
nil: a quantile scale maps many values to one bucket.
The samples' extent of the bucket a range element stands for, {lo, hi}: the first
sample or the threshold below, the last sample or the threshold above. nil for an
empty domain or range, or an element not in the range.
@spec new() :: t()
A quantile scale with no samples and no range.
Identity.
Identity: a quantile scale has no padding.
The n โ 1 interior quantiles, the thresholds.
Sets the range, a list; answers the struct.
quantiles/1; the count is ignored.