NAG Library Routine Document
G01ASF
1 Purpose
G01ASF produces a specified number of box and whisker plots on a character printing device, with a chosen number of character positions in each direction.
2 Specification
SUBROUTINE G01ASF ( 
PRT, M, N, X, LDX, NSTEPX, NSTEPY, PLOT, LDPLOT, WORK, IWORK, IFAIL) 
INTEGER 
M, N(M), LDX, NSTEPX, NSTEPY, LDPLOT, IWORK(LDX), IFAIL 
REAL (KIND=nag_wp) 
X(LDX,M), WORK(5*M) 
CHARACTER(1) 
PRT, PLOT(LDPLOT,NSTEPX) 

3 Description
G01ASF produces a series of box and whisker plots representing $m$ data batches each of size ${n}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,m$. A box and whisker plot is a diagrammatic representation of the fivepoint summary of a data batch. The plot consists of a box spanning the hinges with the median indicated by a third line and two whiskers to represent the extreme values. The fivepoint summary is calculated internally and is returned in the workspace array.
The plot is returned in the character array
PLOT. The size of the plot may be controlled using the parameters
NSTEPX and
NSTEPY. Optionally the plot can be output to an external file, in which case output is directed to the current advisory message unit as defined by
X04ABF.
An axis corresponding to the $y$ axis is drawn and annotated and data points are plotted to the nearest character position.
4 References
Erickson B H and Nosanchuk T A (1985) Understanding Data Open University Press, Milton Keynes
Tukey J W (1977) Exploratory Data Analysis Addison–Wesley
5 Parameters
 1: PRT – CHARACTER(1)Input
On entry: indicates whether the box and whisker plot is to be output to an external file.
 ${\mathbf{PRT}}=\text{'N'}$
 The box and whisker plot is not output to an external file.
 ${\mathbf{PRT}}=\text{'P'}$
 The box and whisker plot is output to the current advisory message unit as defined by X04ABF.
Constraint:
${\mathbf{PRT}}=\text{'P'}$ or $\text{'N'}$.
 2: M – INTEGERInput
On entry: $m$, the number of data batches that are to be represented.
Constraint:
${\mathbf{M}}>0$.
 3: N(M) – INTEGER arrayInput
On entry:
${\mathbf{N}}\left(\mathit{i}\right)$ contains the number of observations in the
$\mathit{i}$th batch,
${n}_{\mathit{i}}$, for
$\mathit{i}=1,2,\dots ,m$.
If ${n}_{i}<5$ the $i$th batch is omitted from the plot.
Constraint:
at least one ${\mathbf{N}}\left(\mathit{i}\right)$ must be greater than or equal to $5$, for $\mathit{i}=1,2,\dots ,m$.
 4: X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: the
$i$th column of
X must contain the data for the
$\mathit{i}$th batch, that is
${\mathbf{X}}\left(\mathit{j},\mathit{i}\right)$ must contain the
$\mathit{j}$th observation of the
$\mathit{i}$th batch, for
$\mathit{i}=1,2,\dots ,m$ and
$\mathit{j}=1,2,\dots ,{n}_{\mathit{i}}$.
 5: LDX – INTEGERInput
On entry: the first dimension of the array
X and the dimension of the array
IWORK as declared in the (sub)program from which G01ASF is called.
Constraint:
${\mathbf{LDX}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{{\mathbf{N}}\left(i\right)\right\}$.
 6: NSTEPX – INTEGERInput
On entry: the number of character positions to be plotted in the $x$direction.
Constraint:
${\mathbf{NSTEPX}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(19,\left(15\times {\mathbf{M}}/4+9\right)\right)$.
 7: NSTEPY – INTEGERInput
On entry: the number of character positions to be plotted in the $y$direction.
Constraint:
${\mathbf{NSTEPY}}\ge 9$.
 8: PLOT(LDPLOT,NSTEPX) – CHARACTER(1) arrayOutput
On exit: contains the box and whisker plots.
 9: LDPLOT – INTEGERInput
On entry: the first dimension of the array
PLOT as declared in the (sub)program from which G01ASF is called.
Constraint:
${\mathbf{LDPLOT}}\ge {\mathbf{NSTEPY}}$.
 10: WORK($5\times {\mathbf{M}}$) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{WORK}}\left(\mathit{j}\right)$, for $\mathit{j}=\left(i1\right)\times 5+1,\dots ,\left(i1\right)\times 5+5$, contains the fivepoint summary of the $i$th batch.
 11: IWORK(LDX) – INTEGER arrayWorkspace
 12: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{N}}\left(\mathit{i}\right)<5$ for some $\mathit{i}$, for $\mathit{i}=1,2,\dots ,m$. For each batch where this occurs, $5$ crosses are plotted in a vertical line to indicate that insufficient data was provided to produce a fivepoint summary and boxplot for that particular batch.
 ${\mathbf{IFAIL}}=2$
On entry,
${\mathbf{NSTEPX}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(19,15\times {\mathbf{M}}/4+9\right)$. This indicates that the data region defined by
NSTEPX is too small to produce the required plot.
 ${\mathbf{IFAIL}}=3$
On entry,  ${\mathbf{NSTEPY}}<9$. 
 ${\mathbf{IFAIL}}=4$
On entry,  ${\mathbf{LDPLOT}}<{\mathbf{NSTEPY}}$. 
 ${\mathbf{IFAIL}}=5$
On entry,  ${\mathbf{PRT}}\ne \text{'P'}$ or $\text{'N'}$. 
 ${\mathbf{IFAIL}}=6$
On entry, ${\mathbf{LDX}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{N}}\left(i\right)\right)$, for $i=1,2,\dots ,m$.
 ${\mathbf{IFAIL}}=7$
The number of observations in all batches is less than $5$.
 ${\mathbf{IFAIL}}=8$
On entry, the data values are all identical.
7 Accuracy
If the range of observations in a particular batch is too small to allow each item of the fivepoint summary to be plotted separately, then a sequence of stars are plotted at the median point of the batch to indicate that the full boxplot could not be plotted.
The time taken by G01ASF increases with $m$ and ${n}_{i}$, for $\mathit{i}=1,2,\dots ,m$.
9 Example
The following program produces a box and whisker plot for each one of $5$ data batches of sizes $5$, $6$, $8$, $8$ and $7$ respectively and prints the $5$ box and whisker plots on the current advisory message unit.
9.1 Program Text
Program Text (g01asfe.f90)
9.2 Program Data
Program Data (g01asfe.d)
9.3 Program Results
Program Results (g01asfe.r)