View Source Tucan.Grid (tucan v0.4.1)

Helper utilities for customizing a plot's grid.

Summary

Functions

Set a specific color to the grid for both x and y axes.

Set a specific color to the grid for the given channel.

Sets the dash style of the grid.

Enables or disables the grid for the plot.

Enable or disable the grid of a specific channel

Sets the opacity of the grid lines.

Sets the width of the grid lines.

Functions

@spec set_color(vl :: VegaLite.t(), color :: String.t()) :: VegaLite.t()

Set a specific color to the grid for both x and y axes.

This will raise if any of the two x, y channels are not encoded.

See also set_color/3

Examples

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_color("red")
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"gridColor":"red"},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"gridColor":"red"},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_color(vl, channel, color)

View Source
@spec set_color(vl :: VegaLite.t(), channel :: atom(), color :: String.t()) ::
  VegaLite.t()

Set a specific color to the grid for the given channel.

This will raise if the channel is not encoded.

Examples

A scatter plot with the y-axis grid colored red and x-axis grid with a custom RGB color:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_color(:y, "red")
|> Tucan.Grid.set_color(:x, "#2A32F4")
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"gridColor":"#2A32F4"},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"gridColor":"red"},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_dash_style(vl, channel, stroke, space)

View Source
@spec set_dash_style(
  vl :: VegaLite.t(),
  channel :: atom(),
  stroke :: pos_integer(),
  space :: pos_integer()
) :: VegaLite.t()

Sets the dash style of the grid.

stroke and space are alternative lengths for the dashed grid lines in pixels.

This will raise if the channel is not encoded.

Examples

A scatter plot with the different dashed styles across the two axes:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_dash_style(:x, 10, 2)
|> Tucan.Grid.set_dash_style(:y, 2, 10)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"gridDash":[10,2]},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"gridDash":[2,10]},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_enabled(vl, enabled)

View Source
@spec set_enabled(vl :: VegaLite.t(), enabled :: boolean()) :: VegaLite.t()

Enables or disables the grid for the plot.

Notice that the grid is enabled by default.

See also set_enabled/3 for enabling/disabling specific axis' grid.

Examples

A scatter plot with the grid disabled:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_enabled(false)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"grid":false},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"grid":false},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_enabled(vl, channel, enabled)

View Source
@spec set_enabled(vl :: VegaLite.t(), channel :: atom(), enabled :: boolean()) ::
  VegaLite.t()

Enable or disable the grid of a specific channel

This will raise if the channel is not encoded.

Examples

A scatter plot with the y-axis grid disabled:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_enabled(:y, false)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"grid":false},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_opacity(vl, channel, opacity)

View Source
@spec set_opacity(vl :: VegaLite.t(), channel :: atom(), opacity :: float()) ::
  VegaLite.t()

Sets the opacity of the grid lines.

If not set it defaults to 1.

This will raise if the channel is not encoded.

Examples

A scatter plot with the y-axis grid colored red and x-axis grid with a custom RGB color and opacity values set. Also the width is increased to make the opacity changes more clear.

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_color(:x, "red")
|> Tucan.Grid.set_color(:y, "cyan")
|> Tucan.Grid.set_opacity(:x, 0.1)
|> Tucan.Grid.set_opacity(:y, 0.8)
|> Tucan.Grid.set_width(:x, 3)
|> Tucan.Grid.set_width(:y, 3)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"gridColor":"red","gridOpacity":0.1,"gridWidth":3},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"gridColor":"cyan","gridOpacity":0.8,"gridWidth":3},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_width(vl, channel, width)

View Source
@spec set_width(vl :: VegaLite.t(), channel :: atom(), width :: pos_integer()) ::
  VegaLite.t()

Sets the width of the grid lines.

If not set it defaults to 1.

This will raise if the channel is not encoded.