VISUALISE FROM ggsql:airquality
DRAW ribbon
MAPPING Date AS x, Wind AS ymin, Temp AS ymaxRibbon
Layers are declared with the
DRAWclause. 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 that is unanchored from zero.
Aesthetics
The following aesthetics are recognised by the ribbon layer.
Required
- Primary axis (e.g.
x): Position along the primary axis - Secondary axis min (e.g.
ymin): Lower position along the secondary axis. - Secondary axis max (e.g.
ymax): Upper position along the secondary 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: Position adjustment. One of'identity'(default),'stack','dodge', or'jitter'
Data transformation
The ribbon layer sorts the data along its primary axis
Orientation
Ribbon layers are sorted and connected along their primary axis. The orientation is deduced directly from the mapping, because the interval is mapped to the secondary axis. To create a vertical ribbon layer you map the independent variable to y instead of x and the interval to xmin and xmax (assuming a default Cartesian coordinate system).
Examples
A ribbon plot with arbitrary values as minima/maxima
Ribbon plots are great for showing the range of some aggregation.
// Weekly aggregation of temperature
SELECT
Week,
MAX(Temp) AS MaxTemp,
AVG(Temp) AS MeanTemp,
MIN(Temp) AS MinTemp
FROM ggsql:airquality
GROUP BY Week
VISUALISE Week AS x
DRAW ribbon
MAPPING MinTemp AS ymin, MaxTemp AS ymax
SETTING opacity => 0.5
DRAW line
MAPPING MeanTemp AS y