4. The main plotting directive

Radian supports a number of common plot types (lines, points, bars, areas, etc.), and these plots can be composed in a number of ways. Multiple plots can be superimposed on a single plot frame, or multiple plot frames can be laid out using a VBox/HBox layout scheme (ADD LINK).

Each plot frame is defined by a <plot> directive, which contains a number of plot type directives (e.g. <lines>, <points>, etc.). The attributes of the <plot> directive provide information about the overall structure of the plot such as its size, axis labelling, title, and so on. As with all Radian directives, extra variables for use in Radian expressions within the plot can also be specified as attributes.


The <plot> directive

The <plot> directive has a large number of attributes. The most important are those for specifying plot size (WIDTH, HEIGHT and ASPECT) and for specifying axis characteristics. There are four axes: X and Y (bottom and left) and X2 and Y2 (top and right), each associated with a corresponding “data path” attribute of the same name, and each having a set of formatting attributes. In the table below, the symbol “◊” stands for one of X, Y, X2 or Y2.

Attributes

Name     Description
RANGE- Specify coordinate range for plot
RANGE Specify both x- and y-coordinate ranges for plot together
AXIS- Either on/off to allow (default) or suppress axis display, or a tick specification
AXIS--TRANSFORM If present, one of linear (default) or log
AXIS--LABEL Either on/off to allow (default) or suppress axis labelling, or a label string (when on is used, the axis label is taken from metadata where possible)
AXIS--TICK-FORMAT Format string for axis tick display (see below)
AXIS--TICK-SIZES Tick sizes for axis ticks (see below)
AXIS--TICK-SIZE Tick size for major axis ticks
AXIS--MINOR-TICK-SIZE Tick size for minor axis ticks
AXIS--END-TICK-SIZE Tick size for axis end ticks
AXIS--TICKS Number of major ticks or explicit tick values (see below)
AXIS--MINOR-TICKS Number of minor ticks per major axis tick
AXIS--TICK-PADDING Padding between axis ticks and tick labels
TICK-SIZES Default tick sizes for all axes (see below)
TICK-SIZE Default tick size for major axis ticks for all axes (see below)
MINOR-TICK-SIZE Default tick size for minor axis ticks for all axes (see below)
END-TICK-SIZE Default tick size for axis end ticks for all axes (see below)
MINOR-TICKS Default number of minor ticks per major axis tick for all axes
TICK-PADDING Default padding between axis ticks and tick labels for all axes
NO-DATA Message to display when no data is available
X Data path defining x-coordinate for plot data
Y Data path defining y-coordinate for plot data
X2 Data path defining x2-coordinate for plot data
Y2 Data path defining y2-coordinate for plot data
TITLE Plot title
WIDTH Plot width in pixels
HEIGHT Plot height in pixels
ASPECT Plot aspect ratio
ZOOM-X Presence/absence or fraction: enable X-zooming
ZOOM-Y Presence/absence or fraction: enable Y-zooming
ZOOM-2D Presence/absence: enable 2-D pan and zoom
LEGEND-SWITCHES Enable interactive on/off switching of traces via the plot legend
STROKE-SWITCH Labels for stroke switching UI
SELECT-X Provide UI for selecting between x-variables of plot
SELECT-Y Provide UI for selecting between y-variables of plot
FONT-SIZE Standard font attribute (axes and annotations)
FONT-FAMILY Standard font attribute (axes and annotations)
FONT-STYLE Standard font attribute (axes and annotations)
FONT-WEIGHT Standard font attribute (axes and annotations)
FONT-VARIANT Standard font attribute (axes and annotations)
TITLE-FONT-SIZE Standard font attribute (plot title)
TITLE-FONT-FAMILY Standard font attribute (plot title)
TITLE-FONT-STYLE Standard font attribute (plot title)
TITLE-FONT-WEIGHT Standard font attribute (plot title)
TITLE-FONT-VARIANT Standard font attribute (plot title)
MARKER Standard paint attribute
MARKER-SIZE Standard paint attribute
FILL Standard paint attribute
FILL-OPACITY Standard paint attribute
STROKE Standard paint attribute
STROKE-WIDTH Standard paint attribute
STROKE-OPACITY Standard paint attribute


The user interface elements of Radian will be getting a complete overhaul at some point soon, so the behaviour of the zoom and stroke and variable selection attributes of <plot> are likely to change.

Body

The body of a <plot> directive should contain directives specifying the data to be drawn into the plot (using <lines>, <points>, etc.). There may also be <plot-options> directives specifying paint and calculational attributes common to all plot directives.

The <plot-options> directive can be used to wrap inner plotting directives that share plotting options. For instance, the following example plots two line graphs that share a stroke width value. Note how attribute variables defined in the main <plot> directive propagate down to the inner plotting directives, and also how attributes set in <plot-options> can be overridden by the inner plotting directives:

<plot height=300 aspect=3 xs="[[seq(-1,1,100)]]">
  <plot-options stroke-width=2 stroke="red">
    <lines x="[[xs]]" y="[[-x**3+x+1]]"/>
    <lines x="[[xs]]" y="[[x**2]]" stroke="blue"/>
  </plot-options>
</plot>

Paint attributes

There are a number of attributes shared among several plotting directives, used to specify line stroke, area fill, or plot marker styles. The names of most of these attributes correspond directly to attributes from the definition of the SVG image format.

Name     Description
MARKER Marker name to use for point plots: one of circle, cross, diamond, square, triangle-down, triangle-up or a URL referencing an image file to use as a marker
MARKER-SIZE Marker size to use for point plots (as an area in square pixels: i.e. MARKER="square" MARKER-SIZE=100 would give squares 10 pixels by 10 pixels in size
FILL Fill colour for markers and area plots (usual CSS syntax for colours, i.e. names, #XXX, #XXXXXX, rgb(r, g, b) or rgba(r, g, b, a)
FILL-OPACITY Opacity for fill colours for markers and area plots (from 0 to 1)
STROKE Stroke colour for line plots and marker outlines (usual CSS syntax for colours, i.e. names, #XXX, #XXXXXX, rgb(r, g, b) or rgba(r, g, b, a)
STROKE-WIDTH Line width for line plots
STROKE-OPACITY Opacity for stroke colours for line plots and marker outlines (from 0 to 1)


All of these attributes can be supplied as single values, e.g. FILL="red", or as functions of data expressed as Radian expressions, e.g. using a palette expression (ADD LINK):

<plot height=600 aspect=1
      axis-x-label="Age" axis-y-label="Height" stroke="none"
      marker="circle" marker-size=75>
  <points x="[[fam.age]]" y="[[fam.height]]"
          fill="[[@P{D female #FF7F7F; male #7F7FFF}(fam.sex)]]">
  </points>
</plot>

Many more examples of the use of paint attributes can be seen in the example gallery.