Rectangle

Layers are declared with the DRAW clause. Read the documentation for this clause for a thorough description of how to use it.

Rectangles can be used to draw heatmaps or indicate ranges.

Aesthetics

The following aesthetics are recognised by the rectangle layer.

Required

  • Pick two of the following for the primary axis:
    • Center (e.g. x)
    • width
    • Start position (e.g. xmin). Unavailable when the center is discrete.
    • End position (e.g. xmax). Unavailable when the center is discrete.

Alternatively, use only the center, which will set width to 1 by default.

  • Pick two of the following for the secondary axis:
    • Center (e.g. y)
    • height: The size of the rectangle in the vertical dimension.
    • Start position (e.g. ymin). Unavailable when the center is discrete.
    • End position (e.g. ymax) Unavailable when the center is discrete.

Alternatively, use only the center, which will set height to 1 by default.

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 colours.
  • linewidth: The width of the contour lines.
  • linetype: The dash pattern of the contour line.

Settings

  • position: Determines the position adjustment to use for the layer (default is 'identity')

Data transformation.

When the primary aesthetics are continuous, primary data is reparameterised to {start, end}, e.g. xmin and xmax. When the secondary aesthetics are continuous, secondary data is reparameterised to {start, end}, e.g. ymin and ymax.

Orientation

The rectangle layer has no orientation. The axes are treated symmetrically.

Examples

Just using x and y. Note that width and height are set to 1.

VISUALISE Day AS x, Month AS y, Temp AS colour FROM ggsql:airquality
  DRAW rect 

Customising width and height with either the MAPPING or SETTING clauses.

VISUALISE Day AS x, Month AS y, Temp AS colour FROM ggsql:airquality
  DRAW rect MAPPING 0.5 AS width SETTING height => 0.8

If x is continuous, then width can be variable. Likewise for y and height.

SELECT *, Temp / (SELECT MAX(Temp) FROM ggsql:airquality) AS norm_temp 
FROM ggsql:airquality
VISUALISE 
    Day AS x, 
    Month AS y, 
    Temp AS colour
  DRAW rect 
    MAPPING 
      norm_temp AS width, 
      norm_temp AS height

Using top, right, bottom, left parameterisation instead.

SELECT
  MIN(Date) AS start,
  MAX(Date) AS end,
  MIN(Temp) AS min,
  MAX(Temp) AS max
FROM ggsql:airquality
GROUP BY
  WEEKOFYEAR(Date)

VISUALISE start AS xmin, end AS xmax, min AS ymin, max AS ymax
  DRAW rect

Using a rectangle as an annotation.

VISUALISE FROM ggsql:airquality
  DRAW rect MAPPING
    '1973-06-01' AS xmin,
    '1973-06-30' AS xmax,
    50 AS ymin, 
    100 AS ymax,
    'June' AS colour
  DRAW line MAPPING Date AS x, Temp AS y