-
Notifications
You must be signed in to change notification settings - Fork 4
Polish area and ribbon layers #97
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
+332
−44
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dac164c
ribbon translates ymin/ymax
teunbrand da9a98b
translate linetype linewidth
teunbrand 04989d8
forgot name change
teunbrand 9876aa7
add linewidth aesthetic
teunbrand ffec7d9
implement area stacking
teunbrand 7ee2e3d
add some docs
teunbrand 3b59156
streamline geom specifics
teunbrand c1613ee
extract logic to functions
teunbrand 178670b
add tests for area stacking and ribbon translation
teunbrand 8d8dd6f
cargo fmt
teunbrand 0330cb3
Merge branch 'main' into ribbon_area
teunbrand c6e9114
remove colour as aesthetic
teunbrand 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| title: "Area" | ||
| --- | ||
|
|
||
| > Layers are declared with the [`DRAW` clause](../clause/draw.qmd). Read the documentation for this clause for a thorough description of how to use it. | ||
|
|
||
| The area layer is used to display absolute amounts over a sorted x-axis. It can be seen as a [ribbon layer](ribbon.qmd) where the `ymin` is anchored at zero. | ||
|
|
||
| ## Aesthetics | ||
| The following aesthetics are recognised by the area layer. | ||
|
|
||
| ### Required | ||
| * `x`: Position along the x-axis. | ||
| * `y`: Position along the y-axis. | ||
|
|
||
| ### Optional | ||
| * `stroke`: The colour of the contour lines. | ||
| * `fill`: The colour of the inner area. | ||
| * `colour`: Shorthand for setting `stroke` and `fill` simultaneously. | ||
| * `opacity`: The opacity of the colours. | ||
| * `linewidth`: The width of the contour lines. | ||
|
|
||
| ## Settings | ||
| * `stacking`: Determines how multiple groups are displayed. One of the following: | ||
| * `'off'`: The groups `y`-values are displayed as-is (default). | ||
| * `'on'`: The `y`-values are stacked per `x` position, accumulating over groups. | ||
| * `'fill'`: Like `'on'` but displayed as a fraction of the total per `x` position. | ||
|
|
||
| ## Data transformation | ||
| The area layer does not transform its data but passes it through unchanged. | ||
|
|
||
| ## Examples | ||
|
|
||
| Create a typical area chart | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE FROM ggsql:airquality | ||
| DRAW area | ||
| MAPPING Date AS x, Wind AS y | ||
| ``` | ||
|
|
||
| We can reshape the data to 'long format' from our wide format. | ||
|
|
||
| ```{ggsql} | ||
| CREATE TABLE long_airquality AS | ||
| SELECT * FROM ggsql:airquality | ||
| UNPIVOT( | ||
| Value FOR Series IN (Temp, Wind) | ||
| ) AS u; | ||
| ``` | ||
|
|
||
| Which means we can display multiple series at once, by mapping the identifier to an aesthetic. | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE Date AS x, Value AS y FROM long_airquality | ||
| DRAW area MAPPING Series AS colour | ||
| ``` | ||
|
|
||
| We can stack the series by using `stacking => 'on'`. The line serves as a reference for 'unstacked' data. | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE Date AS x, Value AS y, Series AS colour FROM long_airquality | ||
| DRAW area SETTING stacking => 'on', opacity => 0.5 | ||
| DRAW line | ||
| ``` | ||
|
|
||
| When `stacking => 'fill'` we're plotting stacked proportions. These only make sense if every series is measured in the same absolute unit. (Wind and temperature have different units and the temperature is not absolute.) | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE Date AS x, Value AS y, Series AS colour FROM long_airquality | ||
| DRAW area SETTING stacking => '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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| title: "Ribbon" | ||
| --- | ||
|
|
||
| > Layers are declared with the [`DRAW` clause](../clause/draw.qmd). Read the documentation for this clause for a thorough description of how to use it. | ||
| The ribbon layer is used to display extrema over a sorted x-axis. It can be seen as an [area chart](area.qmd) that is unanchored from zero. | ||
|
|
||
| ## Aesthetics | ||
| The following aesthetics are recognised by the ribbon layer. | ||
|
|
||
| ### Required | ||
| * `x`: Position along the x-axis | ||
| * `ymin`: Lower position along the y-axis. | ||
| * `ymax`: Upper position along the y-axis. | ||
|
|
||
| ### Optional | ||
| * `stroke`: The colour of the contour lines. | ||
| * `fill`: The colour of the inner area. | ||
| * `colour`: Shorthand for setting `stroke` and `fill` simultaneously. | ||
| * `opacity`: The opacity of the colours. | ||
| * `linewidth`: The width of the contour lines. | ||
|
|
||
| ## Settings | ||
| The ribbon layer has no additional settings. | ||
|
|
||
| ## Data transformation | ||
| The ribbon layer does not transform its data but passes it through unchanged. | ||
|
|
||
| ## Examples | ||
|
|
||
| A ribbon plot with arbitrary values as minima/maxima | ||
|
|
||
| ```{ggsql} | ||
| VISUALISE FROM ggsql:airquality | ||
| DRAW ribbon | ||
| MAPPING Date AS x, Wind AS ymin, Temp AS ymax | ||
| ``` | ||
|
|
||
| Ribbon plots are great for showing the range of some aggregation. | ||
|
|
||
| ```{ggsql} | ||
| // Weekly aggregation of temperature | ||
| SELECT | ||
| WEEKOFYEAR(Date) AS Week, | ||
| MAX(Temp) AS MaxTemp, | ||
| MEAN(Temp) AS MeanTemp, | ||
| MIN(Temp) AS MinTemp | ||
| FROM ggsql:airquality | ||
| GROUP BY WEEKOFYEAR(Date) | ||
| VISUALISE Week AS x | ||
| DRAW ribbon | ||
| MAPPING MinTemp AS ymin, MaxTemp AS ymax | ||
| SETTING opacity => 0.5 | ||
| DRAW line | ||
| MAPPING MeanTemp AS y | ||
| ``` |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should find a unified position adjustment approach, but let's keep it for now