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
The `FACET` clause allows you to split your data, by one or two variables, and plot each group as a small version of the plot: a technique called 'small multiples'. The technique is great for preventing overplotting. Because each small plot shares the same positional scales by default, visual comparisons between groups become easy.
6
+
7
+
## Clause syntax
8
+
The `FACET` syntax contains a number of subclauses that are all optional
9
+
10
+
```ggsql
11
+
FACET <column> BY <column>
12
+
SETTING <parameter> => <value>, ...
13
+
```
14
+
15
+
The first `column` is mandatory. It names a column in the layer data that will be used for splitting the data. If the layer data does not contain the column the behavior for that layer depends on the `missing` parameter of the facet.
16
+
17
+
### `BY`
18
+
The optional `BY` clause is used to define an additional column to split the data by. If it is missing the small multiples are laid out in a grid with the facet panels filling the cells in a row-wise fashion. If `BY` is present then the categories of the first `column` defines the rows of the grid and the categories of the second `column` the columns of the grid. Each multiple is then positioned according to that.
19
+
20
+
### `SETTING`
21
+
This clause behaves much like the `SETTINGS` clause in `DRAW`, in that it allows you to fine-tune specific behavior of the faceting. The following parameters exist:
22
+
23
+
*`free`: Controls whether the positional scales are independent across the small multiples. Permissible values are:
24
+
*`null` or omitted (default): Shared/fixed scales across all panels
*`missing`: Determines how layers behave when the faceting column is missing. It can take two values: `'repeat'` (default), and `'null'`. If `'repeat'` is set, then the layer data is repeated in each panel. If `'null'`, then such layers are only displayed if a null panel is shown, as controlled by the facet scale.
29
+
*`ncol`: The number of panel columns to use when faceting by a single variable. Default is 3 when fewer than 6 categories are present, 4 when fewer than 12 categeries are present and otherwise 5. When the `BY`-clause is used to set a second faceting variable, the `ncol` setting is not allowed. There is no `nrow` setting as this is derived from the number of panels and the `ncol` setting.
30
+
31
+
### Facet variables as aesthetics
32
+
When you apply faceting to a plot you are creating new aesthetics you can control. For 1-dimensional faceting (no `BY` clause) the aesthetic is called `panel` and for 2-dimensional faceting the aesthetics are called `row` and `column`. You can read more about these aesthetics in [their documentation](../scale/aesthetic/Z_facetting.qmd)
33
+
34
+
### Customizing facet strip labels
35
+
To customize facet strip labels (e.g., renaming categories), use the `RENAMING` clause on the facet scale:
ggsql provides one or two aesthetics related to faceting. These are special in the sense that they do not alter the display of the single data values, but rather alter in which plot they appear. While it is possible to map to these aesthetics in a layer they are most often applied globally as part of the [`FACET` clause](../../clause/facet.qmd).
6
+
7
+
The aesthetics provided are either `panel` (for 1-dimensional faceting) or `row` and `column` (for 2-dimensional faceting). These aesthetics have to compatible with the facet clause: it is not possible to map to `panel` in a 2-dimensional faceting plot nor is it possible to map `row` and `column` in a 1-dimensional plot.
8
+
9
+
## Literal values
10
+
Scales for facet aesthetics never use an output range and always relate to the input range. This means that no concept of literal values applies.
11
+
12
+
## Scale types
13
+
Since panels are discrete by nature it is not possible to have a continuous scale for a facet. If continuous data is mapped to a facet aesthetic, a binned scale will be applied by default.
14
+
15
+
```{ggsql}
16
+
VISUALISE Date AS x, Temp AS y FROM ggsql:airquality
17
+
DRAW line
18
+
FACET Date
19
+
SETTING free => 'x'
20
+
SCALE panel
21
+
SETTING breaks => 'month'
22
+
SCALE x
23
+
SETTING breaks => 'weeks'
24
+
```
25
+
26
+
In order to show data where the facet variable is null, it is necessary to explicitly include `null` in the input range of a facet aesthetic scale. Just like discrete positional aesthetics. You can also use `RENAMING` on the scale to customize facet strip labels.
0 commit comments