|
| 1 | +--- |
| 2 | +title: "Area" |
| 3 | +--- |
| 4 | + |
| 5 | +> 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. |
| 6 | +
|
| 7 | +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. |
| 8 | + |
| 9 | +## Aesthetics |
| 10 | +The following aesthetics are recognised by the area layer. |
| 11 | + |
| 12 | +### Required |
| 13 | +* `x`: Position along the x-axis. |
| 14 | +* `y`: Position along the y-axis. |
| 15 | + |
| 16 | +### Optional |
| 17 | +* `stroke`: The colour of the contour lines. |
| 18 | +* `fill`: The colour of the inner area. |
| 19 | +* `colour`: Shorthand for setting `stroke` and `fill` simultaneously. |
| 20 | +* `opacity`: The opacity of the colours. |
| 21 | +* `linewidth`: The width of the contour lines. |
| 22 | + |
| 23 | +## Settings |
| 24 | +* `stacking`: Determines how multiple groups are displayed. One of the following: |
| 25 | + * `'off'`: The groups `y`-values are displayed as-is (default). |
| 26 | + * `'on'`: The `y`-values are stacked per `x` position, accumulating over groups. |
| 27 | + * `'fill'`: Like `'on'` but displayed as a fraction of the total per `x` position. |
| 28 | + |
| 29 | +## Data transformation |
| 30 | +The area layer does not transform its data but passes it through unchanged. |
| 31 | + |
| 32 | +## Examples |
| 33 | + |
| 34 | +Create a typical area chart |
| 35 | + |
| 36 | +```{ggsql} |
| 37 | +VISUALISE FROM ggsql:airquality |
| 38 | +DRAW area |
| 39 | + MAPPING Date AS x, Wind AS y |
| 40 | +``` |
| 41 | + |
| 42 | +We can reshape the data to 'long format' from our wide format. |
| 43 | + |
| 44 | +```{ggsql} |
| 45 | +CREATE TABLE long_airquality AS |
| 46 | +SELECT * FROM ggsql:airquality |
| 47 | +UNPIVOT( |
| 48 | + Value FOR Series IN (Temp, Wind) |
| 49 | +) AS u; |
| 50 | +``` |
| 51 | + |
| 52 | +Which means we can display multiple series at once, by mapping the identifier to an aesthetic. |
| 53 | + |
| 54 | +```{ggsql} |
| 55 | +VISUALISE Date AS x, Value AS y FROM long_airquality |
| 56 | + DRAW area MAPPING Series AS colour |
| 57 | +``` |
| 58 | + |
| 59 | +We can stack the series by using `stacking => 'on'`. The line serves as a reference for 'unstacked' data. |
| 60 | + |
| 61 | +```{ggsql} |
| 62 | +VISUALISE Date AS x, Value AS y, Series AS colour FROM long_airquality |
| 63 | + DRAW area SETTING stacking => 'on', opacity => 0.5 |
| 64 | + DRAW line |
| 65 | +``` |
| 66 | + |
| 67 | +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.) |
| 68 | + |
| 69 | +```{ggsql} |
| 70 | +VISUALISE Date AS x, Value AS y, Series AS colour FROM long_airquality |
| 71 | + DRAW area SETTING stacking => 'fill' |
| 72 | +``` |
0 commit comments