You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Fix annotation layer query generation for geoms with no required aesthetics
When annotation layers have no required aesthetics (e.g., rule geom) and only
non-positional scalar parameters, process_annotation_layer now adds a dummy
column to generate valid SQL instead of malformed empty VALUES clause.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* adopt linear layer functionality into rule layer
* repurpose linear tests for rule
* repurpose docs
* eradicate linear layer
* grammar/highlighting fixes
* remove `intercept`
* adapt docs
* create `setup_layer()` method
* fix issue with expanding scales
* cargo fmt
* account for #249
* replace orientation blurb with position blurb
* compute decisions up front
* clarifying comment
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: doc/syntax/layer/type/rule.qmd
+41-3Lines changed: 41 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ title: "Rule"
6
6
7
7
The rule layer is used to draw reference lines perpendicular to an axis at specified values. This is useful for adding thresholds, means, medians, event markers, cutoff dates or other guides to the plot. The lines span the full width or height of the panels.
8
8
9
+
Additionally, the rule layer can draw diagonal reference lines by specifying a `slope` along with a position (`x` or `y`). The position acts as the intercept term in the linear equation. This is useful for adding regression lines, diagonal guides, or mathematical functions to plots.
10
+
9
11
> The rule layer doesn't have a natural extent along the secondary axis. The secondary scale range can thus not be deduced from rule layers. If the rule layer is the only layer in the visualisation, you must specify the position scale range manually.
10
12
11
13
## Aesthetics
@@ -15,19 +17,27 @@ The following aesthetics are recognised by the rule layer.
15
17
* Primary axis (e.g. `x` or `y`): Position along the primary axis.
16
18
17
19
### Optional
20
+
*`slope` The $\beta$ in the equations described below. Defaults to 0.
18
21
*`colour`/`stroke`: The colour of the line
19
22
*`opacity`: The opacity of the line
20
23
*`linewidth`: The width of the line
21
24
*`linetype`: The type of the line, i.e. the dashing pattern
22
25
23
26
## Settings
24
-
The rule layer has no additional settings.
27
+
*`position`: Position adjustment. One of `'identity'` (default), `'stack'`, `'dodge'`, or `'jitter'`
25
28
26
29
## Data transformation
27
-
The rule layer does not transform its data but passes it through unchanged.
30
+
31
+
For diagonal lines, the position aesthetic determines the intercept:
32
+
33
+
*`y = a, slope = β` creates the line: $y = a + \beta x$ (line passes through $(0, a)$)
34
+
*`x = a, slope = β` creates the line: $x = a + \beta y$ (line passes through $(a, 0)$)
35
+
36
+
Note that `slope` represents $\Delta x/\Delta y$ (change in x per unit change in y) when using `x` mapping, not the traditional $\Delta y/\Delta x$.
37
+
The default slope is 0, creating horizontal lines when `y` is given and vertical lines when `x` is given.
28
38
29
39
## Orientation
30
-
Rules are drawn perpendicular to their primary axis. The orientation is deduced directly from the mapping. To create a horizontal rule you map the values to `y` instead of `x` (assuming a default Cartesian coordinate system).
40
+
The orientation is deduced directly from the mapping. See the ['Data transformation'](#data-transformation) section for details.
31
41
32
42
## Examples
33
43
@@ -73,3 +83,31 @@ DRAW line
73
83
DRAW rule
74
84
MAPPING value AS y, label AS colour FROM thresholds
75
85
```
86
+
87
+
Add a diagnoal reference line to a scatterplot by using `slope`
88
+
89
+
```{ggsql}
90
+
VISUALISE FROM ggsql:penguins
91
+
DRAW point MAPPING bill_len AS x, bill_dep AS y
92
+
PLACE rule SETTING slope => 0.4, y => -1
93
+
```
94
+
95
+
Add multiple reference lines with different colors from a separate dataset. Note we're mapping from data here, so we use `DRAW` instead of `PLACE`.
0 commit comments