Quantile scale for mapping sorted data to discrete buckets.
Unlike quantize scales which divide the domain uniformly, quantile scales divide the data into buckets with equal numbers of samples. This is useful when you want each color/category to represent the same number of data points.
Examples
# Divide data into quartiles
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100]
scale = Visualize.Scale.Quantile.new()
|> Visualize.Scale.Quantile.domain(data)
|> Visualize.Scale.Quantile.range(["Q1", "Q2", "Q3", "Q4"])
Visualize.Scale.Quantile.apply(scale, 2) # => "Q1"
Visualize.Scale.Quantile.apply(scale, 5) # => "Q2"
Visualize.Scale.Quantile.apply(scale, 100) # => "Q4"
# Get the quantile thresholds
Visualize.Scale.Quantile.quantiles(scale) # => [3.5, 6.0, 8.5]
Summary
Functions
Maps a value to a discrete range value based on quantiles
Returns 0: a quantile scale has no bandwidth
Identity: a quantile scale always maps into its range
Sets the domain from a list of sample values.
Returns nil: a quantile scale maps many values to one bucket
Returns the extent of domain values that map to a given range value.
Creates a new quantile scale
Identity
Identity: a quantile scale has no padding
Returns the quantile thresholds
Sets the discrete output range
Alias of apply/2, kept for one release (spec/03 §1.3)
Returns the quantile thresholds (quantiles/1); the count is ignored
Types
Functions
Maps a value to a discrete range value based on quantiles
@spec bandwidth(t()) :: 0
Returns 0: a quantile scale has no bandwidth
Identity: a quantile scale always maps into its range
Sets the domain from a list of sample values.
The domain values will be sorted and used to compute quantile thresholds.
Returns nil: a quantile scale maps many values to one bucket
Returns the extent of domain values that map to a given range value.
Returns {min, max} for the values that map to the specified discrete value.
@spec new() :: t()
Creates a new quantile scale
Identity
Identity: a quantile scale has no padding
Returns the quantile thresholds
Sets the discrete output range
Alias of apply/2, kept for one release (spec/03 §1.3)
Returns the quantile thresholds (quantiles/1); the count is ignored