VISUALISE FROM ggsql:airquality
DRAW area
MAPPING Date AS x, Wind AS yArea
Layers are declared with the
DRAWclause. 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 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 settingstrokeandfillsimultaneously.opacity: The opacity of the colours.linewidth: The width of the contour lines.
Settings
position: Determines the position adjustment to use for the layer (default is'stack')
Data transformation
The area layer does not transform its data but passes it through unchanged.
Examples
Create a typical area chart
We can reshape the data to ‘long format’ from our wide format.
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.
VISUALISE Date AS x, Value AS y FROM long_airquality
DRAW area MAPPING Series AS colourBy default the areas are stacked on top of each other. If you’d rather see all with a 0 baseline set the position to identity
VISUALISE Date AS x, Value AS y, Series AS colour FROM long_airquality
DRAW area SETTING position => 'identity', opacity => 0.5When position => 'stack_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.)
VISUALISE Date AS x, Value AS y, Series AS colour FROM long_airquality
DRAW area SETTING position => 'fill'An alternative is to center the stacks to create a steamgraph
VISUALISE Date AS x, Value AS y, Series AS colour FROM long_airquality
DRAW area SETTING position => 'stack', center => true