Skip to content

Commit 8eb2317

Browse files
committed
document group/reduce
1 parent 3749b6d commit 8eb2317

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

README.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,36 +1019,55 @@ Bins on *y*. Groups on on *x* and first of *z*, *fill*, or *stroke*, if any.
10191019

10201020
[Source](./src/transforms/group.js) · [Examples](https://observablehq.com/@data-workflows/plot-group)
10211021

1022-
TODO Describe output aggregation. Supported reducers:
1023-
1024-
* *first* -
1025-
* *last* -
1026-
* *count* -
1027-
* *sum* -
1028-
* *proportion* -
1029-
* *proportion-facet* -
1030-
* *deviation* -
1031-
* *min* -
1032-
* *max* -
1033-
* *mean* -
1034-
* *median* -
1035-
* *variance* -
1022+
The group transforms take two arguments: *outputs* and *inputs*. The input data is grouped on one or several input channels (for example on *x*), and a new data array is created for each group. Each property set in the *outputs* object creates an aggregation channel, that receives as input the groups, and reduces them to a value for each group. A value channel is defined for each aggregation channel, for example *y* when grouping on *x*.
1023+
1024+
Supported reducers:
1025+
1026+
* *first* - first element of the group, in input order
1027+
* *last* - last element of the group, in input order
1028+
* *count* - number of elements in the group
1029+
* *sum* - sum of the values of the elements in the group; defaults to* the *count* if the value channel is not defined
1030+
* *proportion* - *sum* of the group divided by the total *sum* of all groups
1031+
* *proportion-facet* - *sum* of the group divided by the total *sum* of groups in the current facet
1032+
* *deviation* - standard deviation of the values in the group
1033+
* *min* - minimum of the values in the group
1034+
* *max* - maximum of the values in the group
1035+
* *mean* - mean of the values in the group
1036+
* *median* - median of the values in the group
1037+
* *variance* - variance of the values in the group
10361038

10371039
#### Plot.group(*outputs*, *options*)
10381040

1039-
Groups on *x*, *y*, and the first of *z*, *fill*, or *stroke*, if any.
1041+
Groups on *x*, *y*, and the first of *z*, *fill*, or *stroke*, if any. The value channel is the input with the same name as the aggregation channel.
1042+
1043+
Examples:
1044+
1045+
```js
1046+
Plot.group({fill: "count"}, {
1047+
x: "island",
1048+
y: "species"
1049+
})
1050+
```
1051+
1052+
```js
1053+
Plot.group({fill: "max"}, {
1054+
x: d => d.date.getUTCDate(),
1055+
y: d => d.date.getUTCMonth(),
1056+
fill: "temp_max"
1057+
})
1058+
```
10401059

10411060
#### Plot.groupX(*outputs*, *options*)
10421061

1043-
Groups on *x* and the first of *z*, *fill*, or *stroke*, if any.
1062+
Groups on *x* and the first of *z*, *fill*, or *stroke*, if any. The value channel is *y*.
10441063

10451064
#### Plot.groupY(*outputs*, *options*)
10461065

1047-
Groups on *y* and the first of *z*, *fill*, or *stroke*, if any.
1066+
Groups on *y* and the first of *z*, *fill*, or *stroke*, if any. The value channel is *x*.
10481067

10491068
#### Plot.groupZ(*outputs*, *options*)
10501069

1051-
Groups on the first of *z*, *fill*, or *stroke*, if any; if none of *z*, *fill*, or *stroke* are channels, then all data (within each facet) is placed into a single group.
1070+
Groups on the first of *z*, *fill*, or *stroke*, if any; if none of *z*, *fill*, or *stroke* are channels, then all data (within each facet) is placed into a single group. The value channel is the input with the same name as the aggregation channel.
10521071

10531072
### Map
10541073

0 commit comments

Comments
 (0)