-
Notifications
You must be signed in to change notification settings - Fork 18
Add aggregate functionality for base layers #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
a12e198
first pass
thomasp85 bb16c9c
Merged upstream/main into issue160-aggregate
thomasp85 778b6ac
support numeric axis geoms
thomasp85 0a1b214
support range geoms
thomasp85 218f302
reformat
thomasp85 f14a017
Merge commit 'c3e234b942094f05ddefac1ae6d9b407c54771c3'
thomasp85 8c5845f
support aggregation in segment
thomasp85 2cb0216
allow orientation in range and ribbon for aggregation case
thomasp85 cc390bd
rename to percentile
thomasp85 4476005
make aggregates parametric
thomasp85 3f1a433
reformat
thomasp85 6147ccc
clippy be happy
thomasp85 1c613e4
ensure multiple aggregates give rise to multiple groups
thomasp85 f3081a3
begin to document
thomasp85 56780b0
polygon and path doesn't allow aggregation
thomasp85 802f1f1
Add documentation for non-range layers
thomasp85 c6dd4a9
rethink aggregation
thomasp85 caf0a8e
add back long-form aggregation
thomasp85 564673c
reformat
thomasp85 88a707b
fix aggregation of time-dependent layers
thomasp85 b1938d8
add additional aggregations + examples
thomasp85 c40ea31
Apply suggestions from code review
thomasp85 d76825d
apply doc changes to all layers
thomasp85 bcbedba
support first and last in ANSI, add diff
thomasp85 905063d
support tile
thomasp85 840fc6e
defer scaling of aggregated columns
thomasp85 bdcd700
update SKILL
thomasp85 65c504c
reformat
thomasp85 a2b24b9
Merge aggregate_domain_aesthetics and supports_aggregate into one
thomasp85 7014e93
avoid twice parsing
thomasp85 5ce2ddc
refactor aggregate parsing
thomasp85 4aa4159
better warning
thomasp85 95d4df1
add finer test
thomasp85 134f847
Merge commit '23c50f1a67872808838933f2a7a287871e82c446'
thomasp85 ee49998
appease our dear lord and master clippy
thomasp85 c574e45
Apply suggestions from code review
thomasp85 fe8fae0
improve docs
thomasp85 ba0bf3f
implement suggestions from review
thomasp85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,7 @@ criterion/ | |
|
|
||
| # Claude Code specific | ||
| .claude/ | ||
| memory | ||
|
|
||
| # R specific | ||
| *.Rproj.user | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,48 @@ The `SETTING` clause can be used for two different things: | |
| #### Position | ||
| A special setting is `position` which controls how overlapping objects are repositioned to avoid overlapping etc. Position adjustments have special mapping requirements so all position adjustments will not be relevant for all layer types. Different layers have different defaults as detailed in their documentation. You can read about each different position adjustment at [their own documentation sites](../index.qmd#position-adjustments). | ||
|
|
||
| #### Aggregate | ||
| Some layers support aggregation of their data through the `aggregate` setting. Their documentation will state this. `aggregate` collapses each group to a single row, replacing every numeric mapping in place with its aggregated value. Groups are defined by `PARTITION BY` together with all discrete mappings. | ||
|
|
||
| The `aggregate` setting takes a single string or an array of strings. Each string is one of: | ||
|
|
||
| * **Untargeted** — `'<func>'` (no prefix). With one untargeted aggregation, the function applies to every numeric mapping that doesn't have a targeted aggregation. With two untargeted aggregations, the first is used for the lower side of range layers (e.g. `x`/`xmin`) plus all non-range layers, and the second is used for the upper side of range layers (e.g. `xend`/`xmax`). More than two untargeted aggregations is not allowed. | ||
| * **Targeted** — `'<aes>:<func>'`. Applies `func` to the named aesthetic only (`<aes>` is a name like `x`, `y`, `xmin`, `xmax`, `xend`, `yend`, `color`, `size`, …). A target overrides any untargeted aggregation for that aesthetic. | ||
|
|
||
| A numeric mapping is dropped from the layer with a warning, when it has neither a target nor an applicable default. | ||
|
|
||
| ##### Aggregate functions | ||
| Aggregation can either be a simple function or a band function. The simple functions are: | ||
|
|
||
| * `'count'`: Non-null tally of the bound column. | ||
| * `'sum'` and `'prod'`: The sum or product | ||
| * `'min'`, `'max'`: Extremes | ||
| * `'range'` (max - min), `'mid'` (min + max) / 2 | ||
| * `'mean'`, and `'median'`: Central tendency | ||
| * `'geomean'`, `'harmean'`, and `'rms'`: Geometric, harmonic, and root-mean-square | ||
| * `'sdev'`, `'var'`, `'iqr'`, and `'se'`: Standard deviation, variance, interquartile range, and standard error | ||
| * `'p05'`, `'p10'`, `'p25'`, `'p50'`, `'p75'`, `'p90'`, and `'p95'`: Percentiles | ||
| * `'first'` and `'last'`: The first or last value in the group, in row order. Note that the row order within a group is engine-defined unless the source query has an `ORDER BY` — these are most useful when the upstream SQL provides an explicit ordering. | ||
| * `'diff'`: `last - first`. The change between the first and last value in row order — same ordering caveat applies. | ||
|
|
||
| For band functions you combine an offset with an expansion, potentially multiplied. An example could be `'mean-1.96sdev'` which does exactly what you'd expect it to be. The general form is `<offset>±<multiplier><expansion>` with `<multiplier>` being optional (defaults to `1`). | ||
|
|
||
| Allowed offsets are: `'mean'`, `'median'`, `'geomean'`, `'harmean'`, `'rms'`, `'sum'`, `'prod'`, `'min'`, `'max'`, `'mid'`, and `'p05'`–`'p95'` | ||
|
|
||
| Allowed expansions are: `'sdev'`, `'se'`, `'var'`, `'iqr'`, and `'range'` | ||
|
Comment on lines
+105
to
+107
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For overview purposes a table could be nice, but it is not at all necessary |
||
|
|
||
| ##### Exploded aggregation | ||
| 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 `/`: | ||
|
|
||
| * `aggregate => ('y:min', 'y:max')` → rows tagged `'min'`, `'max'`. | ||
| * `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). | ||
| * `aggregate => ('y:min', 'y:max', 'color:sum', 'color:prod')` → rows tagged `'min/sum'`, `'max/prod'`. | ||
| * `aggregate => ('y:mean', 'y:max', 'color:mean', 'color:prod')` → rows tagged `'mean'`, `'max/prod'` (the duplicate `'mean'` collapses). | ||
|
|
||
| When several aesthetics are targeted with the same number of functions, they explode in lockstep: row 1 uses each aesthetic's first function, row 2 the second, and so on. Aesthetics with a single function — and the unprefixed defaults — are reused unchanged across every row. Mixing different numbers of aggregation metrics above 1 across aesthetics is not allowed. | ||
|
|
||
| In the single-row (reduction) case aggregation applies in place — no `REMAPPING` is needed and no synthetic column is added. Only the multi-row (explosion) case described above introduces the synthetic `aggregate` column. | ||
|
|
||
| ### `FILTER` | ||
| ```ggsql | ||
| FILTER <condition> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.