Visualize.Scale.Quantile (Visualize v0.2.35)

Copy Markdown View Source

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

t()

@type t() :: %Visualize.Scale.Quantile{
  domain: [number()],
  range: [any()],
  thresholds: [number()]
}

Functions

apply(scale, value)

@spec apply(t(), number()) :: any()

Maps a value to a discrete range value based on quantiles

bandwidth(quantile)

@spec bandwidth(t()) :: 0

Returns 0: a quantile scale has no bandwidth

clamp(scale, clamp?)

@spec clamp(t(), boolean()) :: t()

Identity: a quantile scale always maps into its range

domain(scale, values)

@spec domain(t(), [number()]) :: t()

Sets the domain from a list of sample values.

The domain values will be sorted and used to compute quantile thresholds.

invert(quantile, value)

@spec invert(t(), any()) :: nil

Returns nil: a quantile scale maps many values to one bucket

invert_extent(scale, value)

@spec invert_extent(t(), any()) :: {number(), number()} | nil

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.

new()

@spec new() :: t()

Creates a new quantile scale

nice(scale)

@spec nice(t()) :: t()

Identity

padding(scale, padding)

@spec padding(t(), number()) :: t()

Identity: a quantile scale has no padding

quantiles(scale)

@spec quantiles(t()) :: [number()]

Returns the quantile thresholds

range(scale, values)

@spec range(t(), [any()]) :: t()

Sets the discrete output range

scale(scale, value)

@spec scale(t(), number()) :: any()

Alias of apply/2, kept for one release (spec/03 §1.3)

ticks(scale, count)

@spec ticks(t(), integer()) :: [number()]

Returns the quantile thresholds (quantiles/1); the count is ignored