Skip to content

Commit 05e37b4

Browse files
committed
Update README, CHANGELOG
1 parent bb5ba64 commit 05e37b4

File tree

3 files changed

+72
-40
lines changed

3 files changed

+72
-40
lines changed

CHANGELOG.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,39 @@
44

55
*Not yet released. These are forthcoming changes in the main branch.*
66

7-
The new [auto mark](./README.md#auto) (Plot.auto) automatically selects a mark type that best represents the dimensions of the given data according to some simple heuristics. The auto mark is intended to support fast exploratory analysis where the goal is to get a useful plot as quickly as possible. It’s also great if you’re new to Plot, since you can get started with a minimal API.
8-
9-
For example,
7+
The new [auto mark](./README.md#auto) ([Plot.auto](./README.md#plotautodata-options)) automatically selects a mark type that best represents the dimensions of the given data according to some simple heuristics. The auto mark is intended to support fast exploratory analysis where the goal is to get a useful plot as quickly as possible. It’s also great if you’re new to Plot, since you can get started with a minimal API. For example,
108

119
[TK image]
1210

1311
```js
1412
Plot.auto(olympians, {x: "height", y: "weight"}).plot()
1513
```
1614

17-
makes a scatterplot (equivalent to [Plot.dot](./README.md#dot));
15+
makes a scatterplot (equivalent to [dot](./README.md#dot));
1816

1917
[TK image]
2018

2119
```js
2220
Plot.auto(aapl, {x: "Date", y: "Close"}).plot()
2321
```
2422

25-
makes a line chart (equivalent to [Plot.lineY](./README.md#line); this mark is chosen because the selected *x* dimension *Date* is temporal and monotonic, _i.e._, the data is in chronological order);
23+
makes a line chart (equivalent to [lineY](./README.md#line); chosen because the selected *x* dimension *Date* is temporal and monotonic, _i.e._, the data is in chronological order);
2624

2725
[TK image]
2826

2927
```js
3028
Plot.auto(penguins, {x: "body_mass_g"}).plot()
3129
```
3230

33-
makes a histogram (equivalent to [Plot.rectY](./README.md#rect) and [Plot.binX](./README.md#bin); chosen because the _body_mass_g_ column is quantitative);
31+
makes a histogram (equivalent to [rectY](./README.md#rect) and [binX](./README.md#bin); chosen because the _body_mass_g_ column is quantitative);
3432

3533
[TK image]
3634

3735
```js
3836
Plot.auto(penguins, {x: "island"}).plot()
3937
```
4038

41-
makes a bar chart (equivalent to [Plot.barY](./README.md#bar) and [Plot.groupX](./README.md#group); chosen because the _island_ column is categorical strings).
39+
makes a bar chart (equivalent to [barY](./README.md#bar) and [groupX](./README.md#group); chosen because the _island_ column is categorical).
4240

4341
Plot’s [axes](./README.md#axis) and [grids](./README.md#axis) are now proper marks, affording a high degree of customizability. This has been one of our most asked-for features, closing more than a dozen feature requests!
4442

@@ -52,11 +50,7 @@ Marks can now declare default margins via the **marginTop**, **marginRight**, **
5250

5351
The new [*mark*.**facetAnchor**](#facetanchor) mark option controls the facets in which the mark will appear when faceting. It defaults to null for all marks except for axis marks, where it defaults to *top-empty* if the axis anchor is *top*, *right-empty* if anchor is *right*, *bottom-empty* if anchor is *bottom*, and *left-empty* if anchor is *left*. This ensures the proper positioning of the axes with respect to empty facets.
5452

55-
The [frame mark](./README.md#frame)’s new **anchor** option allows you to draw a line on one side of the frame (as opposed to the default behavior where a rect is drawn around all four sides). This feature is now used by the *scale*.**line** option for *x* and *y* scales.
56-
57-
The [text mark](./README.md#text) now supports soft hyphens (`\xad`); lines are now eligible to break at soft hyphens, in which case a hyphen (-) will appear at the end of the line before the break.
58-
59-
The [raster mark](./README.md#raster) no longer crashes with an _identity_ color scale.
53+
The [frame mark](./README.md#frame)’s new **anchor** option allows you to draw a line on one side of the frame (as opposed to the default behavior where a rect is drawn around all four sides); this feature is now used by the *scale*.**line** option for *x* and *y* scales. The [text mark](./README.md#text) now supports soft hyphens (`\xad`); lines are now eligible to break at soft hyphens, in which case a hyphen (-) will appear at the end of the line before the break. The [raster mark](./README.md#raster) no longer crashes with an _identity_ color scale. The [voronoi mark](./README.md#plotvoronoidata-options) now correctly respects the **target**, **mixBlendMode**, and **opacity** options.
6054

6155
## 0.6.2
6256

README.md

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -966,64 +966,100 @@ Returns a new arrow with the given *data* and *options*.
966966
967967
### Auto
968968
969-
[Source](./src/marks/auto.js) · [Examples](https://observablehq.com/@observablehq/plot-auto) · Automatically selects a mark type that best represents the dimensions of the given data according to some simple heuristics. While Plot.auto will respect the options you provide, you shouldn’t rely on Plot.auto’s behavior being stable over time; if you want to guarantee a specific chart type, you should specify the marks and transforms explicitly. Plot.auto is intended to support fast exploratory analysis where the goal is to get a useful plot as quickly as possible.
970-
971-
For example, two quantitative dimensions make a scatterplot:
969+
[Source](./src/marks/auto.js) · [Examples](https://observablehq.com/@observablehq/plot-auto) · Automatically selects a mark type that best represents the dimensions of the given data according to some simple heuristics. For example,
972970
973971
```js
974972
Plot.auto(olympians, {x: "height", y: "weight"}).plot()
975-
// equivalent to Plot.dot(olympians, {x: "height", y: "weight"}).plot()
976973
```
977974
978-
A monotonic quantitative dimension and another numeric one make a line chart:
975+
makes a scatterplot (equivalent to [dot](#dot));
979976
980977
```js
981978
Plot.auto(aapl, {x: "Date", y: "Close"}).plot()
982-
// equivalent to Plot.lineY(aapl, {x: "Date", y: "Close"}).plot()
983979
```
984980
985-
One quantitative dimension makes a histogram:
981+
makes a line chart (equivalent to [lineY](#line); chosen because the selected *x* dimension *Date* is temporal and monotonic, _i.e._, the data is in chronological order);
986982
987983
```js
988984
Plot.auto(penguins, {x: "body_mass_g"}).plot()
989-
// equivalent to Plot.rectY(penguins, Plot.binX({y: "count"}, {x: "body_mass_g"})).plot()
990985
```
991986
992-
One ordinal dimension makes a bar chart:
987+
makes a histogram (equivalent to [rectY](#rect) and [binX](#bin); chosen because the _body_mass_g_ column is quantitative);
993988
994989
```js
995990
Plot.auto(penguins, {x: "island"}).plot()
996-
// equivalent to Plot.barY(penguins, Plot.groupX({y: "count"}, {x: "island"})).plot()
997991
```
998992
999-
Opinionated inferences also make it easier to switch which dimensions you’re showing by changing only one thing in the code: you can switch a vertical bar chart to a horizontal one by just switching x to y, instead of also having to switch Plot.barY to Plot.barX and Plot.groupX to Plot.groupY.
993+
makes a bar chart (equivalent to [barY](#bar) and [groupX](#group); chosen because the _island_ column is categorical).
994+
995+
Plot.auto seeks to provide a useful initial plot as quickly as possible through opinionated defaults, and to accelerate exploratory analysis by letting you see different dimensions of data with minimal code. For example, you can switch a vertical bar chart to a horizontal one by changing *x* to *y*; you don’t also have to switch barY to barX and groupX to groupY.
996+
997+
The auto mark supports a subset of the standard [mark options](#mark-options). You must provide at least one position channel:
998+
999+
* **x** - horizontal position
1000+
* **y** - vertical position
1001+
1002+
You may also provide one or more visual encoding channels:
1003+
1004+
* **color** - corresponds to _stroke_ or _fill_ (depending on the chosen mark type)
1005+
* **size** - corresponds to _r_ (and in future, possibly _length_)
1006+
1007+
And you may specify the standard mark-level facet channels:
1008+
1009+
* **fx** - horizontal facet position (column)
1010+
* **fy** - vertical facet position (row)
1011+
1012+
In addition to channel values, the **x**, **y**, **color**, and **size** options may specify reducers. Setting a reducer on **x** implicitly groups or bins on **y**, and likewise setting a reducer on **y** implicitly groups or bins on **x**. Setting a reducer on **color** or **size** groups or bins in both **x** and **y**. Setting a reducer on both **x** and **y** throws an error. To specify a reducer, simply pass the reducer name to the corresponding option. For example:
1013+
1014+
```js
1015+
Plot.auto(penguins, {x: "body_mass_g", y: "count"}).plot()
1016+
```
1017+
1018+
To pass both a value and a reducer, or to disambiguate whether the given string represents a field name or a reducer name, the **x**, **y**, **color**, and **size** options can also be specified as an object with separate **value** and **reduce** properties. For example, to compute the total weight of the penguins in each bin:
1019+
1020+
```js
1021+
Plot.auto(penguins, {x: "body_mass_g", y: {value: "body_mass_g", reduce: "sum"}}).plot()
1022+
```
1023+
1024+
If the **color** channel is specified as a string that is also a valid CSS color, it is interpreted as a constant color. For example, for red bars:
1025+
1026+
```js
1027+
Plot.auto(penguins, {x: "body_mass_g", color: "red"}).plot()
1028+
```
1029+
1030+
This is shorthand for:
1031+
1032+
```js
1033+
Plot.auto(penguins, {x: "body_mass_g", color: {color: "red"}}).plot()
1034+
```
1035+
1036+
To reference a field name instead as a variable color encoding, specify the **color** option as an object with a **value** property:
1037+
1038+
```js
1039+
Plot.auto(penguins, {x: "body_mass_g", color: {value: "red"}}).plot()
1040+
```
1041+
1042+
Alternatively, you can specify a function of data or an array of values, as with a standard mark channel.
10001043
1001-
The options are six channels and a mark override. You must specify either x or y; all others are optional:
1002-
* **x** - corresponds to each mark’s _x_ channel; if specified without _y_, bins or groups on _x_ and shows the count on _y_
1003-
* **y** - corresponds to each mark’s _y_ channel; if specified without _x_, bins or groups on _y_ and shows the count on _x_
1004-
* **fx** - corresponds to each mark’s _fx_ channel
1005-
* **fy** - corresponds to each mark’s _fy_ channel
1006-
* **color** - corresponds to stroke (for line, rule, dot) or fill (for area, rect, bar, cell)
1007-
* **size** - corresponds to the dot’s _r_ channel; setting this always results in a dot mark
1008-
* **mark** - dot, line, area, rule, or bar; each option except dot includes x and y variants, and bar tries picks the appropriate mark from barX, barY, rectX, rectY, rect, or cell
1044+
The auto mark chooses the mark type automatically based on several simple heuristics. These heuristics are not explicitly documented and are likely to evolve over time; see the [source code](./src/marks/auto.js) for details. For more control, you can specify the desired mark type using the **mark** option, which supports the following names:
10091045
1010-
The six channels take one of the following:
1011-
* a string; if not a valid CSS color string or reducer name, interpreted as a field name
1012-
* an accessor function
1013-
* an object _{value, reduce, color}_, where _value_ is a field string or accessor, _reduce_ is a reducer name or function, and _color_ is a color string
1046+
* *area* - [areaY](#plotareaydata-options) or [areaX](#plotareaxdata-options) (or sometimes [area](#plotareadata-options))
1047+
* *bar* - [barY](#plotbarydata-options) or [barX](#plotbarxdata-options); or [rectY](#plotrectydata-options), [rectX](#plotrectxdata-options), or [rect](#plotrectdata-options); or [cell](#plotcelldata-options)
1048+
* *dot* - [dot](#plotdotdata-options)
1049+
* *line* - [lineY](#plotlineydata-options) or [lineX](#plotlinexdata-options) (or sometimes [line](#plotlinedata-options))
1050+
* *rule* - [ruleY](#plotruleydata-options) or [ruleX](#plotrulexdata-options)
10141051
1015-
Setting a reducer on **x** or **y** implicitly groups or bins on the other (y or x). Setting a reducer on **color** or **size** groups or bins in both x and y dimensions. Setting a reducer on both x and y throws an error.
1052+
The chosen mark type depends both on the options you provide (*e.g.*, whether you specified **x** or **y** or both) and the inferred type of the corresponding data values (whether the associated dimension of data is quantitative, categorical, monotonic, *etc.*). While the auto mark will respect the options you provide, you shouldn’t rely on its behavior being stable over time; to guarantee a specific chart type, specify the marks and transforms explicitly.
10161053
10171054
#### Plot.auto(*data*, *options*)
10181055
10191056
<!-- jsdoc auto -->
10201057
10211058
```js
1022-
Plot.auto(athletes, {x: "height", y: "weight", color: "count"})
1023-
// equivalent to Plot.rect(athletes, Plot.bin({fill: "count"}, {x: "height", y: "weight"})).plot()
1059+
Plot.auto(athletes, {x: "height", y: "weight", color: "count"}) // equivalent to rect + bin, say
10241060
```
10251061
1026-
Returns an automatically selected mark with the given *data* and *options* for a quick view of the data. The heuristic for the choice may evolve in the future.
1062+
Returns an automatically-chosen mark with the given *data* and *options*, suitable for a quick view of the data.
10271063
10281064
<!-- jsdocEnd auto -->
10291065

src/marks/auto.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export function auto(data, {x, y, color, size, fx, fy, mark} = {}) {
2323
if (!isOptions(size)) size = makeOptions(size);
2424

2525
// We don’t apply any type inference to the fx and fy channels, if present, so
26-
// these are simply passed-through to the underlying mark’s options.
26+
// these are simply passed-through to the underlying mark’s options. We don’t
27+
// support reducers on the facet channels, but for symmetry with x and y we
28+
// still allow the channels to be specified as {value} objects.
2729
if (isOptions(fx)) ({value: fx} = makeOptions(fx));
2830
if (isOptions(fy)) ({value: fy} = makeOptions(fy));
2931

0 commit comments

Comments
 (0)