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
+34-34Lines changed: 34 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -523,67 +523,67 @@ Note: when the value of the sort option is a string or a function, it is interpr
523
523
524
524
### Facet options
525
525
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:
527
527
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
530
530
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:
532
532
533
533
* facet.**data** - the data to be faceted
534
534
* facet.**x** - the horizontal position; bound to the *fx* scale, which must be *band*
535
535
* facet.**y** - the vertical position; bound to the *fy* scale, which must be *band*
536
536
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.
538
538
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:
555
540
556
541
```js
557
542
Plot.plot({
558
543
facet: {
559
544
data: penguins,
560
-
x:"sex"
545
+
x:"sex",
546
+
y:"island"
561
547
},
562
548
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
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.
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
+
587
587
## Legends
588
588
589
589
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