Skip to content

Commit 802f1f1

Browse files
committed
Add documentation for non-range layers
1 parent 56780b0 commit 802f1f1

6 files changed

Lines changed: 37 additions & 6 deletions

File tree

doc/syntax/layer/type/bar.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ PROJECT TO polar
123123
Use a different type of aggregation for the bars through the `aggregate` setting:
124124

125125
```{ggsql}
126-
VISUALISE species AS y, body_mass AS y FROM ggsql:penguins
126+
VISUALISE species AS x, body_mass AS y FROM ggsql:penguins
127127
DRAW bar
128128
SETTING aggregate => 'mean', fill => 'steelblue'
129129
DRAW range

doc/syntax/layer/type/point.qmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ The following aesthetics are recognised by the point layer.
2323

2424
## Settings
2525
* `position`: Position adjustment. One of `'identity'` (default), `'stack'`, `'dodge'`, or `'jitter'`
26+
* `aggregate`: Aggregation functions to apply per group. Either a single string or an array of strings. See an overview of aggregation function in [the `DRAW` documentation](../../clause/draw.qmd#aggregate) and more information in the *Data transformation* section below.
2627

2728
## Data transformation
28-
The point layer does not transform its data but passes it through unchanged
29+
This layer supports aggregation through the `aggregate` setting. Within each group, defined by `PARTITION BY` and all discrete mappings, aggregates will be calculated and used as the values to plot. Multiple aggregates will give rise to multiple separate groups in the end. These can be distinguished through the added `aggregate` column you can remap to, e.g. `REMAPPING aggregate AS color`
2930

3031
## Orientation
3132
The point layer has no orientation. The axes are treated symmetrically.

doc/syntax/layer/type/rule.qmd

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ The following aesthetics are recognised by the rule layer.
2525

2626
## Settings
2727
* `position`: Position adjustment. One of `'identity'` (default), `'stack'`, `'dodge'`, or `'jitter'`
28+
* `aggregate`: Aggregation functions to apply per group. Either a single string or an array of strings. See an overview of aggregation function in [the `DRAW` documentation](../../clause/draw.qmd#aggregate) and more information in the *Data transformation* section below.
2829

2930
## Data transformation
31+
This layer supports aggregation through the `aggregate` setting. Within each group, defined by `PARTITION BY` and all discrete mappings, aggregates will be calculated and used as the values to plot. Multiple aggregates will give rise to multiple separate groups in the end. These can be distinguished through the added `aggregate` column you can remap to, e.g. `REMAPPING aggregate AS color`
3032

3133
For diagonal lines, the position aesthetic determines the intercept:
3234

@@ -110,4 +112,14 @@ VISUALISE FROM ggsql:penguins
110112
intercept AS y,
111113
label AS colour
112114
FROM lines
113-
```
115+
```
116+
117+
Show a max rule for a timeseries
118+
119+
```{ggsql}
120+
VISUALISE Temp AS y FROM ggsql:airquality
121+
DRAW line
122+
MAPPING Date AS x
123+
DRAW rule
124+
SETTING aggregate => 'max'
125+
```

doc/syntax/layer/type/segment.qmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ For axis-aligned intervals where one coordinate is shared between the start and
2525

2626
## Settings
2727
* `position`: Position adjustment. One of `'identity'` (default), `'stack'`, `'dodge'`, or `'jitter'`
28+
* `aggregate`: Aggregation functions to apply per group. Either a single string or an array of strings. See an overview of aggregation function in [the `DRAW` documentation](../../clause/draw.qmd#aggregate) and more information in the *Data transformation* section below.
2829

2930
## Data transformation
30-
The segment layer does not transform its data but passes it through unchanged.
31+
This layer supports aggregation through the `aggregate` setting. Within each group, defined by `PARTITION BY` and all discrete mappings, aggregates will be calculated and used as the values to plot. Multiple aggregates will give rise to multiple separate groups in the end. These can be distinguished through the added `aggregate` column you can remap to, e.g. `REMAPPING aggregate AS color`
3132

3233
## Orientation
3334
The segment layer has no orientations. The axes are treated symmetrically.

doc/syntax/layer/type/text.qmd

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following aesthetics are recognised by the text layer.
3535
* a 2-element numeric array `[h, v]` where the first number is the horizontal offset and the second number is the vertical offset.
3636
* `format` Formatting specifier, see explanation below.
3737
* `position`: Position adjustment. One of `'identity'` (default), `'stack'`, `'dodge'`, or `'jitter'`
38+
* `aggregate`: Aggregation functions to apply per group. Either a single string or an array of strings. See an overview of aggregation function in [the `DRAW` documentation](../../clause/draw.qmd#aggregate) and more information in the *Data transformation* section below.
3839

3940
### Format
4041
The `format` setting can take a string that will be used in formatting the `label` aesthetic.
@@ -66,7 +67,7 @@ Known formatters are:
6667
* `x`/`X`: Unsigned hexadecimal
6768

6869
## Data transformation
69-
The text layer does not transform its data but passed it through unchanged.
70+
This layer supports aggregation through the `aggregate` setting. Within each group, defined by `PARTITION BY` and all discrete mappings, aggregates will be calculated and used as the values to plot. Multiple aggregates will give rise to multiple separate groups in the end. These can be distinguished through the added `aggregate` column you can remap to, e.g. `REMAPPING aggregate AS color`
7071

7172
## Orientation
7273
The text layer has no orientation. The axes are treated symmetrically.
@@ -146,3 +147,14 @@ PLACE text
146147
x => (40, 50, 50),
147148
y => (19, 19, 15)
148149
```
150+
151+
Use aggregation to place labels at their centroid
152+
153+
```{ggsql}
154+
VISUALISE bill_len AS x, bill_dep AS y FROM ggsql:penguins
155+
DRAW point
156+
MAPPING species AS fill
157+
DRAW text
158+
MAPPING species AS label
159+
SETTING aggregate => 'mean', stroke => 'white', fontweight => 'bold', fontsize => 20
160+
```

src/execute/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,14 @@ fn add_discrete_columns_to_partition_by(
714714
// Build set of excluded aesthetics that should not trigger auto-grouping:
715715
// - Stat-consumed aesthetics (transformed, not grouped)
716716
// - 'label' aesthetic (text content to display, not grouping categories)
717+
// — except when `aggregate` is set on the layer, in which case label
718+
// becomes a legitimate grouping key (e.g. "mean per species, place
719+
// species name at the centroid").
717720
let consumed_aesthetics = layer.geom.stat_consumed_aesthetics();
718721
let mut excluded_aesthetics: HashSet<&str> = consumed_aesthetics.iter().copied().collect();
719-
excluded_aesthetics.insert("label");
722+
if !crate::plot::layer::geom::has_aggregate_param(&layer.parameters) {
723+
excluded_aesthetics.insert("label");
724+
}
720725

721726
for (aesthetic, value) in &layer.mappings.aesthetics {
722727
// Skip position aesthetics - these should not trigger auto-grouping.

0 commit comments

Comments
 (0)