Skip to content

Commit fe8fae0

Browse files
committed
improve docs
1 parent c574e45 commit fe8fae0

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

doc/syntax/clause/draw.qmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ The `aggregate` setting takes a single string or an array of strings. Each strin
8686

8787
A numeric mapping is dropped from the layer with a warning, when it has neither a target nor an applicable default.
8888

89-
The simple functions are:
89+
##### Aggregate functions
90+
Aggregation can either be a simple function or a band function. The simple functions are:
9091

9192
* `'count'`: Non-null tally of the bound column.
9293
* `'sum'` and `'prod'`: The sum or product
@@ -105,7 +106,8 @@ Allowed offsets are: `'mean'`, `'median'`, `'geomean'`, `'harmean'`, `'rms'`, `'
105106

106107
Allowed expansions are: `'sdev'`, `'se'`, `'var'`, `'iqr'`, and `'range'`
107108

108-
You can also target the same aesthetic more than once to produce **multiple rows per group** — one for each function. For example `aggregate => ('y:min', 'y:max')` emits a min row and a max row per group, so a single `DRAW line` produces two summary lines that connect within each group rather than across them. When multiple rows are created, a synthetic `aggregate` column is made that tags each row with the name of the aggregation function. You can use this with a `REMAPPING` to drive another aesthetic — e.g. `REMAPPING aggregate AS stroke` to colour the two lines differently. The column's value is built from the per-row function names of the *exploded* targets, deduplicated, and joined with `/`:
109+
##### Exploded aggregation
110+
You can also target the same aesthetic more than once to produce *multiple rows per group* — one for each function. We call that *exploded aggregation*. For example `aggregate => ('y:min', 'y:max')` emits a min row and a max row per group, so a single `DRAW line` produces two summary lines that connect within each group rather than across them. When multiple rows are created, a synthetic `aggregate` column is made that tags each row with the name of the aggregation function. You can use this with a `REMAPPING` to drive another aesthetic — e.g. `REMAPPING aggregate AS stroke` to colour the two lines differently. The column's value is built from the per-row function names of the *exploded* targets, deduplicated, and joined with `/`:
109111

110112
* `aggregate => ('y:min', 'y:max')` → rows tagged `'min'`, `'max'`.
111113
* `aggregate => ('y:min', 'y:max', 'color:median')` → rows tagged `'min'`, `'max'` (the single-function `color` target is recycled across rows and is not part of the label).

doc/syntax/layer/type/tile.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ DRAW tile
9999
Building a heatmap from raw rows by aggregating per cell.
100100

101101
```{ggsql}
102-
VISUALISE FROM ggsql:airquality
102+
VISUALISE FROM ggsql:penguins
103103
DRAW tile
104-
MAPPING Month AS x, Day AS y, Temp AS fill
105-
SETTING aggregate => 'mean'
104+
MAPPING species AS x, sex AS y, body_mass AS fill
105+
SETTING aggregate => 'mean', opacity => 1
106106
```
107107

108108
Using a tile as an annotation. Note we're using the `PLACE` clause here instead of `DRAW` because we're not mapping from data.

src/plot/layer/geom/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ pub trait GeomTrait: std::fmt::Debug + std::fmt::Display + Send + Sync {
305305

306306
/// True when `parameters["aggregate"]` is set to a non-null string or array.
307307
pub(crate) fn has_aggregate_param(parameters: &HashMap<String, ParameterValue>) -> bool {
308-
matches!(parameters.get("aggregate"), Some(ParameterValue::String(_)) | Some(ParameterValue::Array(_)))
308+
matches!(
309+
parameters.get("aggregate"),
310+
Some(ParameterValue::String(_)) | Some(ParameterValue::Array(_))
311+
)
309312
}
310313

311314
/// Wrapper struct for geom trait objects

0 commit comments

Comments
 (0)