-
Notifications
You must be signed in to change notification settings - Fork 4
New faceting syntax #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New faceting syntax #147
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d77517a
update syntax of facet
thomasp85 2186804
refactor facet, add renaming and property resolving
thomasp85 7f8dd4e
support scaling facets, and mapping to them directly
thomasp85 4aa6626
reformat
thomasp85 c948e84
various small fixes
thomasp85 0e50d5c
Merge commit 'ccf4b28343195f609e4d9c6cf4683713f6c15dfd'
thomasp85 9b4e743
don't add raw facet columns to data
thomasp85 b8bcdc2
Fix labelling for binned facets
thomasp85 34f9f4b
rename to panel and fix last bin label renaming issue
thomasp85 7bd2110
last fixes, I swear
thomasp85 79b767d
docs
thomasp85 8b6ba79
reformat because of course
thomasp85 194918b
silence clippy
thomasp85 2009da3
update based on comments
thomasp85 958ca23
fix example
thomasp85 245d5fd
Merged upstream/main into issue6-faceting
thomasp85 1d4b9ff
Fix build
thomasp85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,42 @@ | ||
| --- | ||
| title: "Create small multiples with `FACET`" | ||
| --- | ||
|
|
||
| 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. | ||
|
|
||
| ## Clause syntax | ||
| The `FACET` syntax contains a number of subclauses that are all optional | ||
|
|
||
| ```ggsql | ||
| FACET <column> BY <column> | ||
| SETTING <parameter> => <value>, ... | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| ### `BY` | ||
| 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. | ||
thomasp85 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### `SETTING` | ||
| 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: | ||
|
|
||
| * `free`: Controls whether the positional scales are independent across the small multiples. Permissible values are: | ||
| * `null` or omitted (default): Shared/fixed scales across all panels | ||
| * `'x'`: Independent x-axis scale, shared y-axis scale | ||
| * `'y'`: Shared x-axis scale, independent y-axis scale | ||
| * `['x', 'y']`: Independent scales for both axes | ||
| * `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. | ||
| * `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. | ||
|
|
||
| ### Facet variables as aesthetics | ||
| 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) | ||
|
|
||
| ### Customizing facet strip labels | ||
| To customize facet strip labels (e.g., renaming categories), use the `RENAMING` clause on the facet scale: | ||
|
|
||
| ```ggsql | ||
| FACET region | ||
| SCALE panel RENAMING 'N' => 'North', 'S' => 'South' | ||
| ``` | ||
|
|
||
| See the [facet scale documentation](../scale/aesthetic/Z_facetting.qmd) for more details on label customization. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --- | ||
| title: Faceting | ||
| --- | ||
|
|
||
| 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). | ||
|
|
||
| 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. | ||
|
|
||
| ## Literal values | ||
| 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. | ||
|
|
||
| ## Scale types | ||
| 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. | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE Date AS x, Temp AS y FROM ggsql:airquality | ||
| DRAW line | ||
| FACET Date | ||
| SETTING free => 'x' | ||
| SCALE panel | ||
| SETTING breaks => 'month' | ||
| SCALE x | ||
| SETTING breaks => 'weeks' | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE sex AS x FROM ggsql:penguins | ||
| DRAW bar | ||
| FACET species | ||
| SCALE panel FROM ['Adelie', null] | ||
| RENAMING null => 'The rest' | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.