Skip to content

Commit de103cd

Browse files
committed
Update README
1 parent bd23744 commit de103cd

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -523,67 +523,67 @@ Note: when the value of the sort option is a string or a function, it is interpr
523523

524524
### Facet options
525525

526-
The *facet* option enables [faceting](https://observablehq.com/@observablehq/plot-facets). When faceting, two additional band scales may be configured:
526+
Plot’s [faceting system](https://observablehq.com/@observablehq/plot-facets) produces small multiples by partitioning data in discrete sets and repeating the plot for each set. When faceting, two additional band scales may be configured:
527527

528-
* **fx** - the horizontal position, a *band* scale
529-
* **fy** - the vertical position, a *band* scale
528+
* *fx* - the horizontal position, a *band* scale
529+
* *fy* - the vertical position, a *band* scale
530530

531-
Similar to [marks](#marks), faceting requires specifying data and at least one of two optional channels:
531+
Faceting may either be specified at the top level of the plot, or on individual marks. When specified at the top level, the following options indicate which data should be faceted, and how:
532532

533533
* facet.**data** - the data to be faceted
534534
* facet.**x** - the horizontal position; bound to the *fx* scale, which must be *band*
535535
* facet.**y** - the vertical position; bound to the *fy* scale, which must be *band*
536536

537-
The facet.**x** and facet.**y** channels are strictly ordinal or categorical (*i.e.*, discrete); each distinct channel value defines a facet. Quantitative data must be manually discretized for faceting, say by rounding or binning. (Automatic binning for quantitative data may be added in the future; see [#14](https://github.com/observablehq/plot/issues/14).)
537+
With top-level faceting, any mark that uses the specified facet data will be faceted by default (see the *mark*.**facet** option below). When specified at the mark level, facets can be defined for each mark individually by specifying the *mark*.**fx** or *mark*.**fy** channel options.
538538

539-
The following *facet* constant options are also supported:
540-
541-
* facet.**marginTop** - the top margin
542-
* facet.**marginRight** - the right margin
543-
* facet.**marginBottom** - the bottom margin
544-
* facet.**marginLeft** - the left margin
545-
* facet.**margin** - shorthand for the four margins
546-
* facet.**grid** - if true, draw grid lines for each facet
547-
* facet.**label** - if null, disable default facet axis labels
548-
549-
Faceting can be explicitly enabled or disabled on a mark with the *facet* option, which accepts the following values:
550-
551-
* *auto* (default) - equivalent to *include* when mark data is strictly equal to facet data; else null
552-
* *include* (or true) - draw the subset of the mark’s data in the current facet
553-
* *exclude* - draw the subset of the mark’s data *not* in the current facet
554-
* null (or false) - repeat this mark’s data across all facets (i.e., no faceting)
539+
Here is an example of top-level faceting:
555540

556541
```js
557542
Plot.plot({
558543
facet: {
559544
data: penguins,
560-
x: "sex"
545+
x: "sex",
546+
y: "island"
561547
},
562548
marks: [
563-
Plot.frame(), // draws an outline around each facet
564-
Plot.dot(penguins, {x: "culmen_length_mm", y: "culmen_depth_mm", fill: "#eee", facet: "exclude"}), // draws excluded penguins on each facet
565-
Plot.dot(penguins, {x: "culmen_length_mm", y: "culmen_depth_mm"}) // draws only the current facet’s subset
549+
Plot.dot(penguins, {x: "culmen_length_mm", y: "culmen_depth_mm"})
566550
]
567551
})
568552
```
569553

570-
When the *include* or *exclude* facet mode is chosen, the mark data must be parallel to the facet data: the mark data must have the same length and order as the facet data. If the data are not parallel, then the wrong data may be shown in each facet. The default *auto* therefore requires strict equality (`===`) for safety, and using the facet data as mark data is recommended when using the *exclude* facet mode. (To construct parallel data safely, consider using [*array*.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on the facet data.)
571-
572-
Alternatively, facets can be defined for each individual mark by specifying the channel options **fx** or **fy**. In that case, the **facet** option only considers the mark data, and the default *auto* setting is equivalent to *include*. Other values of the *facet* option are unchanged: null or false disable faceting, and *exclude* draws the subset of the mark’s data *not* in the current facet.
554+
And here is the equivalent mark-level faceting:
573555

574556
```js
575557
Plot.plot({
576558
marks: [
577-
Plot.dot(penguins, {
578-
x: "culmen_length_mm",
579-
y: "culmen_depth_mm",
580-
fx: "sex",
581-
fy: "island"
582-
})
559+
Plot.dot(penguins, {x: "culmen_length_mm", y: "culmen_depth_mm", fx: "sex", fy: "island"})
583560
]
584561
})
585562
```
586563

564+
Regardless of whether top- or mark-level faceting is used, the *fx* and *fy* channels are strictly ordinal or categorical (*i.e.*, discrete); each distinct channel value defines a facet. Quantitative data must be manually discretized for faceting, say by rounding or binning. (Automatic binning for quantitative data may be added in the future; see [#14](https://github.com/observablehq/plot/issues/14).) When mark-level faceting is used, the *fx* and *fy* channels are computed prior to the [mark’s transform](#transforms), if any (*i.e.*, facet channels are not transformed).
565+
566+
The following top-level facet constant options are also supported:
567+
568+
* facet.**marginTop** - the top margin
569+
* facet.**marginRight** - the right margin
570+
* facet.**marginBottom** - the bottom margin
571+
* facet.**marginLeft** - the left margin
572+
* facet.**margin** - shorthand for the four margins
573+
* facet.**grid** - if true, draw grid lines for each facet
574+
* facet.**label** - if null, disable default facet axis labels
575+
576+
When top-level faceting is used, faceting can be explicitly enabled or disabled on a mark with the *mark*.**facet** option, which accepts the following values:
577+
578+
* *auto* (default) - equivalent to *include* when mark data is strictly equal to facet data; else null
579+
* *include* (or true) - draw the subset of the mark’s data in the current facet
580+
* *exclude* - draw the subset of the mark’s data *not* in the current facet
581+
* null (or false) - repeat this mark’s data across all facets (i.e., no faceting)
582+
583+
When the *include* or *exclude* facet mode is chosen, the mark data must be parallel to the facet data: the mark data must have the same length and order as the facet data. If the data are not parallel, then the wrong data may be shown in each facet. The default *auto* therefore requires strict equality (`===`) for safety, and using the facet data as mark data is recommended when using the *exclude* facet mode. (To construct parallel data safely, consider using [*array*.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on the facet data.)
584+
585+
When mark-level faceting is used, the default *auto* setting is equivalent to *include*: the mark will be faceted if a *mark*.**fx** or *mark*.**fy** channel (or both) is specified. The null or false option will disable faceting, while *exclude* draws the subset of the mark’s data *not* in the current facet.
586+
587587
## Legends
588588

589589
Plot can generate legends for *color*, *opacity*, and *symbol* [scales](#scale-options). (An opacity scale is treated as a color scale with varying transparency.) For an inline legend, use the *scale*.**legend** option:

0 commit comments

Comments
 (0)