View Source Tucan.Scale (tucan v0.2.0)
Utilities for working with Vega-Lite scales.
Scales are functions that transform a domain of data values (numbers, dates, strings, etc.) to a range of visual values (pixels, colors, sizes).
This module exposes various helper functions for setting various scale options like the color scheme, the domain or the scale type.
Summary
Functions
Sets an arbitrary set of options to the given encoding
's scake object.
Sets the color scheme.
Sets the domain for the given encoding channel.
Sets the x-axis domain.
Sets the x axis scale.
Sets the y-axis domain.
Sets the y axis scale.
Types
Functions
@spec put_options(vl :: VegaLite.t(), encoding :: atom(), options :: keyword()) :: VegaLite.t()
Sets an arbitrary set of options to the given encoding
's scake object.
Notice that no validation is performed, any option set will be merged with
the existing scale
options of the given encoding
.
An ArgumentError
is raised if the given encoding channel is not defined.
@spec set_color_scheme( vl :: VegaLite.t(), scheme :: color_scheme(), opts :: keyword() ) :: VegaLite.t()
Sets the color scheme.
You can either set one of the predefined schemes, or an array of colors which will be used as the color range.
The input plot must be a single view with a color encoding defined.
Options
:reverse
(boolean/0
) - If set totrue
the selected scheme is reversed. Ignored if a range is set. The default value isfalse
.
Supported color schemes
All vega supported schemes are supported
by Tucan
.
Categorical Schemes
Categorical color schemes can be used to encode discrete data values, each representing a distinct category.
Sequential Single-Hue Schemes
Sequential color schemes can be used to encode quantitative values. These color ramps are designed to encode increasing numeric values.
Sequential Multi-Hue Schemes
Sequential color schemes can be used to encode quantitative values. These color ramps are designed to encode increasing numeric values, but use additional hues for more color discrimination, which may be useful for visualizations such as heatmaps.
Schemes for Dark Backgrounds
Schemes for Light Backgrounds
Diverging Schemes
Diverging color schemes can be used to encode quantitative values with a meaningful mid-point, such as zero or the average value. Color ramps with different hues diverge with increasing saturation to highlight the values below and above the mid-point.
Cyclical Schemes
Cyclical color schemes may be used to highlight periodic patterns in continuous data. However, these schemes are not well suited to accurately convey value differences.
Examples
Setting a specific color range
Tucan.scatter(:iris, "petal_width", "petal_length", color_by: "species")
|> Tucan.Scale.set_color_scheme(["yellow", "black", "#f234c1"])
You can set any of the predefined color schemes to any plot with a color encoding.
Tucan.scatter(:weather, "date", "temp_max",
x: [time_unit: :monthdate],
y: [aggregate: :mean],
color_by: "temp_max",
color: [aggregate: :mean, type: :quantitative],
width: 400
)
|> Tucan.Scale.set_color_scheme(:redyellowblue)
You can reverse it by setting the :reverse
option:
Tucan.scatter(:weather, "date", "temp_max",
x: [time_unit: :monthdate],
y: [aggregate: :mean],
color_by: "temp_max",
color: [aggregate: :mean, type: :quantitative],
width: 400
)
|> Tucan.Scale.set_color_scheme(:redyellowblue, reverse: true)
@spec set_domain(vl :: VegaLite.t(), channel :: atom(), domain :: term()) :: VegaLite.t()
Sets the domain for the given encoding channel.
domain
can be anything Vega-Lite supports and the validity of it depends on the type
of the encoding's data.
Notice that no validation is performed.
@spec set_x_domain(vl :: VegaLite.t(), min :: number(), max :: number()) :: VegaLite.t()
Sets the x-axis domain.
This is a helper wrapper around set_domain/3
for setting the domain of continuous
scales.
@spec set_x_scale(vl :: VegaLite.t(), scale :: atom()) :: VegaLite.t()
Sets the x axis scale.
Notice that only continuous scales are supported.
@spec set_y_domain(vl :: VegaLite.t(), min :: number(), max :: number()) :: VegaLite.t()
Sets the y-axis domain.
This is a helper wrapper around set_domain/3
for setting the domain of continuous
scales.
@spec set_y_scale(vl :: VegaLite.t(), scale :: atom()) :: VegaLite.t()
Sets the y axis scale.
Notice that only continuous scales are supported.