VegaLite.encode_field

You're seeing just the function encode_field, go back to VegaLite module for more information.
Link to this function

encode_field(vl, channel, field, opts \\ [])

View Source

Specs

encode_field(t(), atom(), String.t(), keyword()) :: t()

Adds field encoding entry to the specification.

A shorthand for encode/3, mapping a data field to a visual channel.

For example, if the data has "price" and "time" fields, you could map "time" to the :x channel and "price" to the :y channel. This, combined with a line mark, would then result in price-over-time plot.

All provided options are converted to channel properties.

Types

Field data type is automatically inferred, but oftentimes needs to be specified explicitly to get the desired result. The :type option can be either of:

  • :quantitative - when the field expresses some kind of quantity, typically numerical

  • :temporal - when the field represents a point in time

  • :nominal - when the field represents a category

  • :ordinal - when the field represents a ranked order. It is similar to :nominal, but there is a clear order of values

  • :geojson - when the field represents a geographic shape adhering to the GeoJSON specification

See the docs for more details on types.

Examples

Vl.new()
|> Vl.data_from_values(...)
|> Vl.mark(:point)
|> Vl.encode_field(:x, "time", type: :temporal)
|> Vl.encode_field(:y, "price", type: :quantitative)
|> Vl.encode_field(:color, "country", type: :nominal)
|> Vl.encode_field(:size, "count", type: :quantitative)
|> ...

Vl.new()
|> Vl.encode_field(:x, "date", time_unit: :month, title: "Month")
|> Vl.encode_field(:y, "price", type: :quantitative, aggregate: :mean, title: "Mean product price")
|> ...

See the docs for more details.