-
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
Open
thomasp85
wants to merge
22
commits into
main
Choose a base branch
from
issue160-aggregate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 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 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
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,47 @@ 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. These layers 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 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 an error. | ||
| * **Targeted** — `'<aes>:<func>'`. Applies `func` to the named aesthetic only (`<aes>` is a user-facing 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 . | ||
|
|
||
| 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. | ||
|
|
||
| The stat exposes a synthetic `aggregate` column tagging each row, which you can pick up 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 lengths above 1 is an error. | ||
|
|
||
| The simple functions are: | ||
|
|
||
| * `'count'`: Non-null tally of the bound column. | ||
| * `'sum'` and `'prod'`: The sum or product | ||
| * `'min'`, `'max'`, `'range'`, and `'mid'`: Extremes, max - min, and (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 | ||
|
|
||
| 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
+101
to
+116
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. This should come before the explanation of how >1 aggregations interact. |
||
|
|
||
| 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.
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.