VISUALISE FROM ggsql:penguins
DRAW point MAPPING bill_len AS x, bill_dep AS y
DRAW linear MAPPING 0.4 AS coef, -1 AS interceptLinear line
Layers are declared with the
DRAWclause. Read the documentation for this clause for a thorough description of how to use it.
The linear layer is used to draw diagonal reference lines based on a coefficient and intercept. This is useful for adding regression lines, diagonal guides, or mathematical functions to plots. The lines extend across the full extent of the x-axis, regardless of the data range. The layer is named for the following formula:
\[ y = a + \beta x \]
Where \(a\) is the intercept and \(\beta\) is the coef.
Aesthetics
The following aesthetics are recognised by the abline layer.
Required
coef: The coefficient/slope of the line i.e. the amount \(y\) increases for every unit of \(x\).intercept: The intercept where the line crosses the y-axis at \(x = 0\).
Optional
colour/stroke: The colour of the lineopacity: The opacity of the linelinewidth: The width of the linelinetype: The type of the line, i.e. the dashing pattern
Settings
The linear layer has no additional settings.
Data transformation
The linear layer does not transform its data but passes it through unchanged.
Examples
Add a simple reference line to a scatterplot:
Add multiple reference lines with different colors from a separate dataset:
WITH lines AS (
SELECT * FROM (VALUES
(0.4, -1, 'Line A'),
(0.2, 8, 'Line B'),
(0.8, -19, 'Line C')
) AS t(coef, intercept, label)
)
VISUALISE FROM ggsql:penguins
DRAW point MAPPING bill_len AS x, bill_dep AS y
DRAW linear
MAPPING
coef AS coef,
intercept AS intercept,
label AS colour
FROM lines