Skip to content

Commit 6e46277

Browse files
committed
Update README
1 parent 38d0c8a commit 6e46277

File tree

1 file changed

+89
-20
lines changed

1 file changed

+89
-20
lines changed

README.md

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,10 @@ The following aggregation methods are supported:
978978
* *mean* - the mean value (average)
979979
* *median* - the median value
980980
* *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.
983985

984986
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*.
985987

@@ -1027,23 +1029,23 @@ Lastly, the bin transform changes the default [mark insets](#marks): rather than
10271029
Plot.rect(athletes, Plot.bin({fillOpacity: "count"}, {x: "weight", y: "height"}))
10281030
```
10291031

1030-
Bins on *x* and *y*. Also groups on the first of *z*, *fill*, or *stroke*, if any.
1032+
Bins on *x* and *y*. Also groups on the first channel of *z*, *fill*, or *stroke*, if any.
10311033

10321034
#### Plot.binX(*outputs*, *options*)
10331035

10341036
```js
10351037
Plot.rectY(athletes, Plot.binX({y: "count"}, {x: "weight"}))
10361038
```
10371039

1038-
Bins on *x*. Also groups on *y* and the first of *z*, *fill*, or *stroke*, if any.
1040+
Bins on *x*. Also groups on *y* and the first channel of *z*, *fill*, or *stroke*, if any.
10391041

10401042
#### Plot.binY(*outputs*, *options*)
10411043

10421044
```js
10431045
Plot.rectX(athletes, Plot.binY({x: "count"}, {y: "weight"}))
10441046
```
10451047

1046-
Bins on *y*. Groups on on *x* and first of *z*, *fill*, or *stroke*, if any.
1048+
Bins on *y*. Groups on on *x* and first channel of *z*, *fill*, or *stroke*, if any.
10471049

10481050
### Group
10491051

@@ -1100,65 +1102,133 @@ If any of **z**, **fill**, or **stroke** is a channel, the first of these channe
11001102
Plot.group({fill: "count"}, {x: "island", y: "species"})
11011103
```
11021104

1103-
Groups on *x*, *y*, and the first of *z*, *fill*, or *stroke*, if any.
1105+
Groups on *x*, *y*, and the first channel of *z*, *fill*, or *stroke*, if any.
11041106

11051107
#### Plot.groupX(*outputs*, *options*)
11061108

11071109
```js
11081110
Plot.groupX({y: "sum"}, {x: "species", y: "body_mass_g"})
11091111
```
11101112

1111-
Groups on *x* and the first of *z*, *fill*, or *stroke*, if any.
1113+
Groups on *x* and the first channel of *z*, *fill*, or *stroke*, if any.
11121114

11131115
#### Plot.groupY(*outputs*, *options*)
11141116

11151117
```js
11161118
Plot.groupY({x: "sum"}, {y: "species", x: "body_mass_g"})
11171119
```
11181120

1119-
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.
11201122

11211123
#### Plot.groupZ(*outputs*, *options*)
11221124

11231125
```js
11241126
Plot.groupZ({x: "proportion"}, {fill: "species"})
11251127
```
11261128

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.
11281130

11291131
### Map
11301132

11311133
[<img src="./img/window.png" width="320" height="198" alt="moving averages of daily highs and lows">](https://observablehq.com/@data-workflows/plot-map)
11321134

1133-
[Source](./src/transforms/map.js) · [Examples](https://observablehq.com/@data-workflows/plot-map)
1135+
[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
11341176

11351177
#### Plot.map(*outputs*, *options*)
11361178

1137-
1179+
```js
1180+
Plot.map({y: "cumsum"}, {y: d3.randomNormal()})
1181+
```
11381182

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*.
11401184

1141-
1185+
#### Plot.mapX(*map*, *options*)
11421186

1143-
#### Plot.mapY(<i>map</i>, *options*)
1187+
```js
1188+
Plot.mapX("cumsum", {x: d3.randomNormal()})
1189+
```
11441190

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*.
11461200

11471201
#### Plot.normalizeX(*options*)
11481202

1149-
1203+
```js
1204+
Plot.normalizeX({y: "Date", x: "Close", stroke: "Symbol"})
1205+
```
1206+
1207+
Similar to [Plot.mapX](#plotmapxmap-options), …
11501208

11511209
#### Plot.normalizeY(*options*)
11521210

1153-
1211+
```js
1212+
Plot.normalizeY({x: "Date", y: "Close", stroke: "Symbol"})
1213+
```
1214+
1215+
Similar to [Plot.mapY](#plotmapymap-options), …
11541216

11551217
#### Plot.windowX(*options*)
11561218

1157-
1219+
```js
1220+
Plot.windowX({y: "Date", x: "Anomaly", k: 24})
1221+
```
1222+
1223+
Similar to [Plot.mapX](#plotmapxmap-options), …
11581224

11591225
#### Plot.windowY(*options*)
11601226

1161-
1227+
```js
1228+
Plot.windowY({x: "Date", y: "Anomaly", k: 24})
1229+
```
1230+
1231+
Similar to [Plot.mapY](#plotmapymap-options), …
11621232

11631233
### Select
11641234

@@ -1192,7 +1262,6 @@ Selects the right-most point of the series.
11921262

11931263
Selects the highest point of the series.
11941264

1195-
11961265
### Stack
11971266

11981267
[<img src="./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

Comments
 (0)