Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_plot_scatter_2var (g01ag)

## Purpose

nag_stat_plot_scatter_2var (g01ag) performs a scatter plot of two variables on a character printing device, with a chosen number of character positions in each direction.

## Syntax

[ifail, y, isort] = g01ag(x, y, nstepx, nstepy, 'nobs', nobs)
[ifail, y, isort] = nag_stat_plot_scatter_2var(x, y, nstepx, nstepy, 'nobs', nobs)
Note: the interface to this routine has changed since earlier releases of the toolbox:
 At Mark 23: output parameters were reordered

## Description

nag_stat_plot_scatter_2var (g01ag) finds the range of the data in each dimension and calculates a step size for each division on the axes; these step sizes are selected from the list
 $0.1,0.15,0.2,0.25,0.4,0.5,0.6,0.75,0.8 × power of ​ 10 .$
The axes are drawn and annotated and data points are plotted on the nearest character position. The character plotted is either a digit $1$ to $9$ for the equivalent number of occurrences of a point at a particular character position, an alphabetic A–Z for $10–35$ occurrences, or * if there are more than $35$ coincident occurrences. Axes are drawn on all sides of the plot with the left-hand and bottom ones annotated; zero axes are also marked if included in the plotting area.
The Fortran logical unit number used for the output is the current advisory message unit number defined for each implementation. This number may be changed by an appropriate call to nag_file_set_unit_advisory (x04ab) before calling nag_stat_plot_scatter_2var (g01ag).

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{nobs}}\right)$ – double array
The values to be plotted in the $x$-direction.
2:     $\mathrm{y}\left({\mathbf{nobs}}\right)$ – double array
The values to be plotted in the $y$-direction.
3:     $\mathrm{nstepx}$int64int32nag_int scalar
The number of steps (character positions) to be plotted in the $x$-direction. If the supplied value of nstepx is less than $10$, the value $10$ will be used by nag_stat_plot_scatter_2var (g01ag). The maximum value for nstepx is the number of character positions available on the chosen output device less $15$, up to a maximum of $133$. If nstepx exceeds $133$ on input, the value $133$ will be used by the function.
4:     $\mathrm{nstepy}$int64int32nag_int scalar
The number of steps (character positions) to be plotted in the $y$-direction. If the supplied value of nstepy is less than $10$, the value $10$ will be used by nag_stat_plot_scatter_2var (g01ag). There is no maximum value for nstepy, but you should bear in mind that $\left({\mathbf{nstepy}}+5\right)$ records (lines) of output are generated by the function.

### Optional Input Parameters

1:     $\mathrm{nobs}$int64int32nag_int scalar
Default: the dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
The number of observations to be plotted.
Constraint: ${\mathbf{nobs}}\ge 1$.

### Output Parameters

1:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).
2:     $\mathrm{y}\left({\mathbf{nobs}}\right)$ – double array
The elements of y are sorted into descending order of magnitude.
3:     $\mathrm{isort}\left({\mathbf{nobs}}\right)$int64int32nag_int array
The key to the descending order of the elements in array y, i.e., ${\mathbf{isort}}\left(\mathit{i}\right)$ contains the position of the value ${\mathbf{y}}\left(\mathit{i}\right)$ in the original array y, for $\mathit{i}=1,2,\dots ,{\mathbf{nobs}}$.

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{nobs}}<1$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Accuracy is limited by the number of plotting points available.

The time taken by nag_stat_plot_scatter_2var (g01ag) may be expected to be approximately proportional to the product ${\mathbf{nobs}}×{\mathbf{nstepx}}×{\mathbf{nstepy}}$.
No blank records are output before or after the plot.
You must make sure that it is permissible to write records containing nstepx characters to the current advisory message unit.

## Example

The data relate to wheat and potato yields in $48$ counties in England in 1936. The example illustrates the use of nag_file_set_unit_advisory (x04ab) to set the logical unit number, used for the output of nag_stat_plot_scatter_2var (g01ag), to a specified value.
```function g01ag_example

fprintf('g01ag example results\n\n');

x = [16.0     16.0     16.4     20.5     18.3     16.3     17.7     15.3;
16.5     16.9     21.9     15.5     15.9     16.1     18.5     12.7;
15.7     14.3     13.9     12.8     12.0     15.6     15.9     16.7;
14.3     14.4     15.2     14.1     15.5     16.5     14.3     13.2;
13.9     14.4     13.5     11.2     14.4     15.5     18.5     16.4;
17.1     16.9     17.5     15.9     19.2     17.7     15.2     17.1];
y = [ 5.3      6.6      6.1      5.5      6.9      6.1      6.4      6.3;
7.8      8.3      5.7      6.2      6.0      6.1      6.6      4.8;
4.9      5.1      5.5      6.7      6.5      5.2      5.2      7.1;
4.9      5.6      6.4      6.9      5.6      6.1      5.7      5.0;
6.5      6.2      5.2      6.6      5.8      6.3      6.3      5.8;
5.9      6.5      5.8      5.7      7.2      6.5      5.4      6.3];
nstepx = int64(40);
nstepy = int64(32);

fprintf(['Plot of wheat (X) and potato (Y) yields in 48 counties in',  ...
'England in 1936.\n\n']);

[~, ~, ~] = g01ag( ...
x, y, nstepx, nstepy)

```
```g01ag example results

Plot of wheat (X) and potato (Y) yields in 48 counties inEngland in 1936.

9.000+....+....+....+....+....+....+....+....+.
.                                        .
.                                        .
.                                        .
.                                        .
8.250+                1                       +
.                                        .
.                                        .
.               1                        .
.                                        .
7.500+                                        +
.                                        .
.                      1                 .
.                1                       .
.         1          1                   .
6.750+      1                                 +
.  1           1     1                   .
.    1    1  1   1 2                     .
.            11   1  1                   .
.          1  113                        .
6.000+              1                         +
.          1    1 11                     .
.          1   1              1          .
.         11  1           1              .
.            1                           .
5.250+        1    12                         +
.          1                             .
.       1  1  1                          .
.      1                                 .
.                                        .
4.500+                                        +
.                                        .
.                                        .
.                                        .
+....+....+....+....+....+....+....+....+.
10.00     14.00     18.00     22.00     26.00
12.00     16.00     20.00     24.00
```