-
Notifications
You must be signed in to change notification settings - Fork 4
Add position to syntax #173
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf2348f
Add position to syntax
thomasp85 d4cedfb
updates based on clippy
thomasp85 3fe7bce
apply suggestions from review
thomasp85 3ab676e
Better visibility to position adjustments in docs
thomasp85 f32cbd9
remove unused var
thomasp85 b306720
Merge commit 'b602c39024f69da55b30a30e89141813cd772257'
thomasp85 2b63e42
fix some clippy warnings
thomasp85 5715d3b
clean up links etc
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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| title: Dodge | ||
| --- | ||
|
|
||
| > Positions are set within the [`DRAW` clause](../../clause/draw.qmd), using the `SETTING` subclause. Read the documentation for this clause for a thorough description of how to use it. | ||
|
|
||
| The dodge adjustment is intended to move entities that share the same position on a discrete scale side by side so they don't overlap. It is most often used for boxplots and violin plots, but can also be used in e.g. bar plots as an alternative to [stacking](stack.qmd). | ||
|
|
||
| ## Position scale requirements | ||
| Dodge doesn't have specific requirements to the scale type of the plot, but will only affect discrete scales (including binned and ordinal). If only one scale is discrete, the dodging happens in that scale's direction. If both scales are discrete, the dodging happens as a 2D grid. | ||
|
|
||
| ## Settings | ||
| Apart from the settings of the layer type, setting `position => 'dodge'` will allow these additional settings: | ||
|
|
||
| * `width`: The total width the dodging will occupy as a proportion of the space available on the scale. Defaults to 0.9 but any defaults from the layer will take precedence. | ||
|
|
||
| ## Examples | ||
|
|
||
| Dodging is default in boxplots (and violin plots) | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, bill_dep AS y, sex AS fill FROM ggsql:penguins | ||
| DRAW boxplot | ||
| ``` | ||
|
|
||
| Turning it off allows you to see the effect of it | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, bill_dep AS y, sex AS fill FROM ggsql:penguins | ||
| DRAW boxplot SETTING position => 'identity' | ||
| ``` | ||
|
|
||
| Dodge can be used for bar plots as an alternative to the default stack | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, island AS fill FROM ggsql:penguins | ||
| DRAW bar SETTING position => 'dodge' | ||
| ``` | ||
|
|
||
| Often `width` is part of the layer settings and gets used directly by the dodge position, but for layers with no inherent width setting dodge provides that setting as well | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, bill_dep AS y, sex AS shape FROM ggsql:penguins | ||
| DRAW point SETTING position => 'dodge', width => 0.5 | ||
| ``` | ||
|
|
||
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,7 @@ | ||
| --- | ||
| title: Identity | ||
| --- | ||
|
|
||
| > Positions are set within the [`DRAW` clause](../../clause/draw.qmd), using the `SETTING` subclause. Read the documentation for this clause for a thorough description of how to use it. | ||
|
|
||
| The identity position is a position adjustment that does nothing, i.e. it leaves the data where it is. It is used to turn off any position adjustments for layers that defaults to non-identity position adjustments. It takes no arguments and has no requirements. |
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,67 @@ | ||
| --- | ||
| title: Jitter | ||
| --- | ||
|
|
||
| > Positions are set within the [`DRAW` clause](../../clause/draw.qmd), using the `SETTING` subclause. Read the documentation for this clause for a thorough description of how to use it. | ||
|
|
||
| Jitter adjustment adds a random offset to the data point to avoid overplotting on discrete axes. It is mainly used in conjunction with point layers. | ||
|
|
||
| ## Position scale requirements | ||
| Jitter requires at least one axis to be discrete as it only jitters along discrete axes. | ||
|
|
||
| ## Settings | ||
| Apart from the settings of the layer type, setting `position => 'jitter'` will allow these additional settings: | ||
|
|
||
| * `width`: The total width the jittering will occupy as a proportion of the space available on the scale. Defaults to 0.9 | ||
| * `dodge`: Should dodging be applied before jittering. The dodging behavior follows the [dodge position](dodge.qmd) behavior? Default to `true` | ||
| * `distribution`: Which kind of distribution should the jittering follow? One of: | ||
| - `'uniform'` (default): Jittering is sampled from a uniform distribution between `-width/2` and `width/2` | ||
| - `'normal'`: Jittering is sampled from a normal distribution with σ as `width/4` resulting in 95% of the points falling inside the given width | ||
| - `'density'`: Jittering follows the density distribution within the group so that the jitter occupies the same area as an equivalent [violin plot](../type/violin.qmd) with density remapped to offset | ||
| - `'intensity'`: Jittering follows the intensity distribution within the group so that the jitter occupies the same area as an equivalent [violin plot](../type/violin.qmd) with intensity remapped to offset | ||
|
|
||
| If `distribution` is either `'density'` or `'intensity'` then one of the axes must be continuous | ||
| * `bandwidth`: A numerical value setting the smoothing bandwidth to use for the `'density'` and `'intensity'` distributions. If absent (default), the bandwidth will be computed using Silverman's rule of thumb. | ||
| * `adjust`: A numerical value as multiplier for the `bandwidth` setting, with 1 as default. | ||
|
|
||
| ## Examples | ||
| When plotting points on a discrete axis they are all placed in the middle | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, bill_dep AS y, sex AS fill FROM ggsql:penguins | ||
| DRAW point | ||
| ``` | ||
|
|
||
| Use jittering to better see the individual points | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, bill_dep AS y, sex AS fill FROM ggsql:penguins | ||
| DRAW point | ||
| SETTING position => 'jitter' | ||
| ``` | ||
|
|
||
| By default, dodging is applied to separate the groups. Turn this off if you want the jitter to occupy the same space regardless of grouping | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, bill_dep AS y, sex AS fill FROM ggsql:penguins | ||
| DRAW point | ||
| SETTING position => 'jitter', dodge => false | ||
| ``` | ||
|
|
||
| Use a `'density'` distribution to also indicate the distribution shape with the jitter | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, bill_dep AS y FROM ggsql:penguins | ||
| DRAW point | ||
| SETTING position => 'jitter', distribution => 'density' | ||
| ``` | ||
|
|
||
| When both axes are discrete the dodging follows a grid | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE species AS x, sex AS y, body_mass AS fill FROM ggsql:penguins | ||
| DRAW point | ||
| SETTING position => 'jitter' | ||
| SCALE BINNED fill | ||
| SETTING breaks => 4, pretty => false | ||
| ``` |
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,61 @@ | ||
| --- | ||
| title: Stack | ||
| --- | ||
|
|
||
| > Positions are set within the [`DRAW` clause](../../clause/draw.qmd), using the `SETTING` subclause. Read the documentation for this clause for a thorough description of how to use it. | ||
|
|
||
| The stack position adjustment works by stacking objects on top of each other. It makes the most sense for layer types where their height is the primary encoding (i.e. they naturally extend from 0). Stack is the default position for bar and area plots | ||
|
|
||
| ## Position scale requirements | ||
| Stack requires a continuous scale with a range mapping (e.g. either `y` + `yend` or `ymin` + `ymax`) and requires all ranges to be positive with a baseline of zero. The axis that satisfies this will be used as the stacking direction | ||
|
|
||
| ## Settings | ||
| Apart from the settings of the layer type, setting `position => 'stack'` will allow these additional settings: | ||
|
|
||
| * `center`: Should the full stack be centered around 0. Can be used in conjunction with area layers to create steamgraphs. Default to `false` | ||
| * `total`: Sets a total value to which each stack height is normalised. Setting this value leads to 'fill' behaviour. Defaults to `null` (no normalisation) | ||
|
|
||
| ## Examples | ||
|
|
||
| Stack is the default for bar and area | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE Day AS x, Wind AS y FROM ggsql:airquality | ||
| DRAW area | ||
| MAPPING Month AS fill | ||
| FILTER Day <= 30 | ||
| SCALE ORDINAL fill | ||
| ``` | ||
|
|
||
| Turn it off to see the effect (stacking is nonsensical for wind measurements) | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE Day AS x, Wind AS y FROM ggsql:airquality | ||
| DRAW area | ||
| MAPPING Month AS fill | ||
| SETTING position => 'identity' | ||
| FILTER Day <= 30 | ||
| SCALE ORDINAL fill | ||
| ``` | ||
|
|
||
| Set `center => true` to create a steamgraph | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE Day AS x, Wind AS y FROM ggsql:airquality | ||
| DRAW area | ||
| MAPPING Month AS fill | ||
| SETTING center => true | ||
| FILTER Day <= 30 | ||
| SCALE ORDINAL fill | ||
| ``` | ||
|
|
||
| Use `total` to see the percentage contribution from each group | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE Day AS x, Wind AS y FROM ggsql:airquality | ||
| DRAW area | ||
| MAPPING Month AS fill | ||
| SETTING total => 100 | ||
| FILTER Day <= 30 | ||
| SCALE ORDINAL fill | ||
| ``` |
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.