Here you find function for generating "Sankey plots", that is plots
used for depicting graphically the contents of a contingency table
using coloured ribbons. A typical use case is for transition matrices:
each ribbon identifies a flow going from the initial to the final
state.

The package contains two functions: the main function is `SankeyPlot`;
the other one, `SP_series`, is a convenience function that makes
things a little easier in some cases.

# SankeyPlot()

```
string SankeyPlot(const matrix X, bundle optbun[null])
```

Draws a Sankey diagram in which each row of `X` is a node on the left,
each column is a node on the right, and the ribbon joining row *i* to
column *j* has a width proportional to `X[i,j]`. Ribbons take the
colour of their originating row. Row nodes are drawn as coloured boxes
on the left, column nodes as boxes on the right, coloured in shades of
grey. The function returns the gnuplot script that was used to produce the
plot, which can be saved, inspected or modified.

## Arguments

- *X*: matrix, non-negative flows. Rows are the left-hand nodes, columns the right-hand nodes. At most 8 rows and 8 columns.
- *opt*: bundle (optional), see below.

## Options

Pass options as members of a bundle.

- *colors*: matrix, row colours, expressed in hexadecimal notation
  (`0xRRGGBB`). Row *i* uses `colors[i]`. The defaults are
  1. 0xFF0000 (red)
  2. 0x0000FF (blue)
  3. 0x00CC00 (green)
  4. 0xBF25B2 (purple)
  5. 0xB58E2C (brown)
  6. 0x8FAAB3 (grey)
  7. 0xFFAA00 (orange)
  8. 0x91A4FF (light blue)
    
- *sidelabels*, 2-element string array: rotated labels placed outside
  the left and right edges of the plot (default: no labels). Note that
  any additional labels in the array do no harm, but will be ignored.
- *title*, string: Plot title. An empty string means no title, as per default.
- *output*, string `"display"` shows it on screen (default); a
   filename (for example `"flows.pdf"` or `"flows.png"`) writes to a
   file, with the format inferred from the extension.

## Labels

Node labels are taken from the row and column names of `X`. If no
names are set, the labels default to `Row 1`, `Row 2`, ... and `Col 1`, `Col 2`, ...

## Return value

A string holding the gnuplot script.

## Limits and notes

- `X` must have at most 8 rows and 8 columns, otherwise the function stops with an error.
- Entries of `X` should be non-negative. Zero entries produce no ribbon.


# SP_series()

```
string SP_series(const series a, const series b, bundle opts[null])
```

Builds the contingency table of two series with `mxtab()` and passes
it to `SankeyPlot()`. The categories of `a` form the left-hand nodes
and the categories of `b` the right-hand nodes; each ribbon's width
reflects the number of observations falling in that combination. If a
series is string-valued, its string labels are used automatically as
row or column names. Otherwise the default `Row n` / `Col n` labels
apply. A simplified versaion of this functionis also available via the
GUI under `View/Graph specified vars`.

## Arguments

- *a*, series: series for the left-hand categories.
- *b*, series: series defining the right-hand categories.
- *opts*, bundle (optional): options bundle, exactly as for `SankeyPlot()`.

## Return value

The gnuplot script string returned by `SankeyPlot()`.

## Notes

- each series can have at most 8 distinct values.
