You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+89-20Lines changed: 89 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -978,8 +978,10 @@ The following aggregation methods are supported:
978
978
**mean* - the mean value (average)
979
979
**median* - the median value
980
980
**variance* - the variance per [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)
981
-
* a function - passed the array of values for each bin
982
-
* an object with a *reduce* method - passed the index for each bin, and all values
981
+
* a function to be passed the array of values for each bin
982
+
* an object with a *reduce* method
983
+
984
+
The *reduce* method is repeatedly passed the index for each bin (an array of integers) and the corresponding input channel’s array of values; it must then return the corresponding aggregate value for the bin.
983
985
984
986
Most aggregation methods require binding the output channel to an input channel; for example, if you want the **y** output channel to be a *sum* (not merely a count), there should be a corresponding **y** input channel specifying which values to sum. If there is not, *sum* will be equivalent to *count*.
985
987
@@ -1027,23 +1029,23 @@ Lastly, the bin transform changes the default [mark insets](#marks): rather than
Groups on *y* and the first of *z*, *fill*, or *stroke*, if any.
1121
+
Groups on *y* and the first channel of *z*, *fill*, or *stroke*, if any.
1120
1122
1121
1123
#### Plot.groupZ(*outputs*, *options*)
1122
1124
1123
1125
```js
1124
1126
Plot.groupZ({x:"proportion"}, {fill:"species"})
1125
1127
```
1126
1128
1127
-
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.
1129
+
Groups on the first channel 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.
1128
1130
1129
1131
### Map
1130
1132
1131
1133
[<imgsrc="./img/window.png"width="320"height="198"alt="moving averages of daily highs and lows">](https://observablehq.com/@data-workflows/plot-map)
[Source](./src/transforms/map.js) · [Examples](https://observablehq.com/@data-workflows/plot-map) · Groups data into series along the *z* dimension, and then applies a mapping function to the values for each series, say to normalize them relative to some basis or to apply a moving average.
1136
+
1137
+
The map transform derives new output channels from corresponding input channels. The output channels have the same length as the input channels; the map transform does not affect the mark’s data or index. The map transform is similar to running [*array*.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on the input channel’s values with the given function; however, the map transform is series-aware: the data is first grouped into series along the *z* dimension in the same fashion as the [area](#area) and [line](#line) marks so that series are processed independently. (You wouldn’t want a moving average to bleed between series, would you?)
1138
+
1139
+
Like the [group](#group) and [bin](#bin) transforms, the base [Plot.map](#plotmapoutputs-options) takes two arguments: an *outputs* object that describes the output channels to compute, and an *options* object that describes the input channels and additional options to propagate. The other map transforms, such as [Plot.normalizeX](#plotnormalizexoptions) and [Plot.windowX](#plotwindowxoptions), call Plot.map internally.
1140
+
1141
+
The following map methods are supported:
1142
+
1143
+
**cumsum* - a cumulative sum
1144
+
* a function to be passed an array of values, returning new values
1145
+
* an object that implements the *map* method
1146
+
1147
+
The *map* method is repeatedly passed the index for each series (an array of integers), the corresponding input channel’s array of values, and the output channel’s array of values; it must populate the slots specified by the index in the output array.
1148
+
1149
+
The Plot.normalizeX and Plot.normalizeY transforms take an additional **basis** option which specifies how to normalize the series values. The following normalization methods are supported:
1150
+
1151
+
**first* - the first value, as in an index chart; the default
1152
+
**last* - the last value
1153
+
**mean* - the mean value (average)
1154
+
**median* - the median value
1155
+
**sum* - the sum of values
1156
+
**extent* - the minimum is mapped to zero, and the maximum to one
1157
+
* a function to be passed an array of values, returning the desired basis
1158
+
1159
+
The Plot.windowX and Plot.windowY transforms take additional options:
1160
+
1161
+
***k** - the window size
1162
+
***shift** - how to align the window: *centered*, *leading*, or *trailing*
1163
+
***reduce** - the aggregation method (window reducer)
1164
+
1165
+
The following window reducers are supported:
1166
+
1167
+
**deviation* - the standard deviation
1168
+
**min* - the minimum
1169
+
**max* - the maximum
1170
+
**mean* - the mean (average)
1171
+
**median* - the median
1172
+
**sum* - the sum of values
1173
+
**variance* - the variance per [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)
1174
+
**difference* - the difference between the last and first window value
1175
+
**ratio* - the ratio of the last and first window value
1134
1176
1135
1177
#### Plot.map(*outputs*, *options*)
1136
1178
1137
-
…
1179
+
```js
1180
+
Plot.map({y:"cumsum"}, {y:d3.randomNormal()})
1181
+
```
1138
1182
1139
-
#### Plot.mapX(<i>map</i>, *options*)
1183
+
Groups on the first channel of *z*, *fill*, or *stroke*, if any, and then for each channel declared in the specified *outputs* object, applies the corresponding map method. Each channel in *outputs* must have a corresponding input channel in *options*.
1140
1184
1141
-
…
1185
+
#### Plot.mapX(*map*, *options*)
1142
1186
1143
-
#### Plot.mapY(<i>map</i>, *options*)
1187
+
```js
1188
+
Plot.mapX("cumsum", {x:d3.randomNormal()})
1189
+
```
1144
1190
1145
-
…
1191
+
Equivalent to Plot.map({x: *map*, x1: *map*, x2: *map*}, *options*), but ignores any of **x**, **x1**, and **x2** not present in *options*.
1192
+
1193
+
#### Plot.mapY(*map*, *options*)
1194
+
1195
+
```js
1196
+
Plot.mapY("cumsum", {y:d3.randomNormal()})
1197
+
```
1198
+
1199
+
Equivalent to Plot.map({y: *map*, y1: *map*, y2: *map*}, *options*), but ignores any of **y**, **y1**, and **y2** not present in *options*.
@@ -1192,7 +1262,6 @@ Selects the right-most point of the series.
1192
1262
1193
1263
Selects the highest point of the series.
1194
1264
1195
-
1196
1265
### Stack
1197
1266
1198
1267
[<imgsrc="./img/stack.png"width="320"height="198"alt="a stacked area chart of revenue by category">](https://observablehq.com/@data-workflows/plot-stack)
0 commit comments