# Statistical Plots Package

A wide variety of plots and charts are used to gain an overview of data from a statistical perspective. Some summarize statistical computations on the data, while others compare data in ways that highlight its properties. This package implements several plotting functions of this class, including Pareto plots and stem-and-leaf plots. Histograms, bar and pie charts are also commonly used in statistical applications, are included in the

*Mathematica* kernel.

Basic statistics-related plots.

Load the plotting package.

## Pareto Plots

The Pareto plot is a quality control plot that combines a bar chart displaying percentages of categories in the data with a line plot showing cumulative percentages of the categories.

ParetoPlot[list] | find frequencies of data in list and create a Pareto plot |

ParetoPlot[{{cat_{1},freq_{1}},{cat_{2},freq_{2}},...}] | create a Pareto plot from the categories with given frequencies |

Pareto plots.

In the most basic form,

ParetoPlot takes a list of data that is assumed to consist of discrete categories. It determines the frequency of each category in the list, converts the frequencies to percentages, and creates the plot.

Create a Pareto plot from a list.

Out[8]= | |

If you have data where the frequencies are precomputed, you can plot it directly by providing

pairs instead of the raw data to

ParetoPlot.

The data quantities have been precomputed for this Pareto plot.

Out[9]= | |

Options for ParetoPlot.

ParetoPlot accepts a number of options common to bar charts and line plots, as detailed in the above table. It also accepts the usual

Graphics options.

The various

and

options are drawn from

BarChart. Most of these behave the same as their

BarChart counterparts. Note that unless the

ChartLabels option is set to

Automatic, it will simply apply the labels cyclically to the bars in the order they appear; they only correspond to the categories in the

Automatic case. The

BarOrigin option applies to the entire plot, not just the bars.

This is a Pareto plot with various options controlling the appearance.

Out[10]= | |

## Pairwise Scatter Plots

The pairs or matrix scatter plot allows the individual columns in a multivariate set of data to be plotted against each other. This can be used to investigate relationships between the variables. The resulting plot is a matrix of subgraphs.

PairwiseScatterPlot[matrix] | plot the columns of the matrix against each other in a pairwise fashion |

A pairwise scatter plot.

The pairs scatter plot forms a matrix of scatter plots from the columns of a multivariate dataset plotted against each other.

PairwiseScatterPlot by default places the first column at the lower left side of the plot, and proceeds to the right and upwards.

Generate data for the examples.

Plot the columns of the data against each other.

Out[14]= | |

Options specific to PairwiseScatterPlot.

A variety of options can be used to control the appearance of the plot. The

DataRanges option accepts a list of range specifications, which can be used to restrict the points to be plotted. The ranges are given as

pairs or

All or

Automatic, used cyclically for all of the columns.

Textual annotations are provided via

DataLabels and

DataTicks. Labels can be supplied for each column via the

DataLabels option, given as a list of labels. Ticks can be specified for each column using the usual graphics ticks syntax; these are drawn at the top and bottom of the corresponding column of the matrix of plots, as well as the right and left sides of the corresponding row. Tick labels are only drawn on alternating sides for each column to prevent labels for adjacent columns from overriding.

The

PlotDirection option specifies the order in which plots are generated in the plot matrix. With the default

{Right, Down}, row

i and column

j of the data are plotted in the

i row and

j column of the grid of scatter plots. The ordering used in versions prior to Version 6.0 can be obtained by setting

PlotDirection->{Right, Up}.

The

PlotStyle option can take either a single style primitive or a matrix of style primitives. If given a matrix, the primitives are applied to the subplots in a cyclic fashion.

Finally, the

DataSpacing option allows the subgraphs to be drawn with varying amounts of space between them. This takes a number or a pair of numbers corresponding to the horizontal and vertical space between each graph. This number is scaled to the size of one of the subgraphs, which range from 0 to 1. You may provide negative numbers for the spacing, which can cause the subgraphs to be arranged in a different order. For example, if you prefer the first column to be at the upper rather than lower left, you can supply the option

DataSpacing. An interesting effect can be derived by setting this option to

, where all the subgraphs are overlaid.

In addition, all of the usual

Graphics options are accepted.

Generate the plot with options controlling its appearance.

Out[15]= | |

## Stem-and-Leaf Plots

The stem-and-leaf plot is generally used to visualize the distribution of real-valued data along with the magnitudes of the individual data values. Each data value is represented by a stem and leaf, where the stem is an integer multiple of a base unit and the leaf is the remainder given to some predetermined number of digits. With a base unit of 10, for instance, 17.3 could be represented as a stem of 1 and a leaf of 7. Leaves are collected onto common stems giving a display analogous to a histogram. The stems play a role similar to histogram bar positions, and the leaves are similar to the histogram bar heights. An advantage of the stem-and-leaf plot is that individual data values can be read directly from the plot. Side-by-side stem-and-leaf plots can be used to compare distributions and magnitudes of two datasets.

StemLeafPlot[vector] | create a stem-and-leaf plot of a vector of data |

StemLeafPlot[vector_{1},vector_{2}] | create a side-by-side stem-and-leaf plot of two vectors of data |

Stem-and-leaf plots.

Here is a vector of real values.

This is a basic stem-and-leaf plot of the data.

Out[17]= | |

For this vector, multiples of 1 are taken as the stems and the fractional parts rounded to one digit are displayed as the leaves. The values 3.1 and 3.2 are displayed on the common stem 3 as leaves 1 and 2.

Here is a second vector of real values.

The two datasets can be compared in a side-by-side stem-and-leaf plot.

Out[19]= | |

A number of options can be applied to control the appearance of the stem-and-leaf plot.

Options for StemLeafPlot.

The value of

StemExponent can be an integer or

Automatic. If it is an integer

, the stem unit is taken to be

. With

StemExponent->Automatic, the exponent is chosen based on the magnitudes of the data.

The

Leaves option value can be

,

, or

None. With

Leaves, leaves are represented as tally marks. With

Leaves->None, leaves are not included in the plot. The setting

Leaves->None is most useful for plotting large datasets as stems and counts instead of displaying all the leaves.

The

ColumnLabels option can be used to specify the labels for the columns of the plot. The

ColumnLabels option value can be a list of a length equal to the number of columns in the plot or

Automatic. With

ColumnLabels->Automatic, the stem column is labeled

, leaf columns are labeled

, and count columns are labeled

.

The

IncludeEmptyStems option specifies whether stems within the data range should be included if they have no leaves. The possible values for this option are

True and

False.

The

IncludeStemUnits option specifies whether or not a reminder of the stem units should be included in the plot. Possible values are

True and

False.

The

IncludeStemCounts option specifies whether a column of counts should be included for each vector of real values plotted. If included, counts are displayed in the rightmost column in a stem-and-leaf plot of a single vector, and in the leftmost and rightmost columns for a side-by-side stem-and-leaf plot. Possible values are

True,

False, and

Automatic. With

IncludeStemCounts->Automatic, counts are only included if the

option is set to

None.

Here is a side-by-side stem-and-leaf plot with stem counts, tally leaves, and nondefault stem units.

Out[20]= | |

This plot displays

sldata including empty stems and using the column labels as a reminder of the units.

Out[21]= | |

A number of options can be applied to control the appearance of the stem-and-leaf plot. The plot is constructed as a

GridBox. In addition to the above options, standard

GridBox options can be used. If

IncludeStemUnits->True,

GridBox options are applied to the grid of stems and leaves, but not to the label for stem units.

Here

sldata is displayed with a frame and nondefault column alignments.

Out[22]= | |

The

StemExponent option has additional options than can be used to further subdivide stem units and label those divisions.

| | |

"UnitDivisions" | 1 | the number of divisions for each stem unit |

"DivisionLabels" | None | a list of labels appended to stem numbers within each unit division |

Suboptions for StemExponent.

The

option specifies the number of stems a base unit should be divided into. The value of

must be a positive integer.

Alternate labeling of subdivisions can be specified via the

option. The value of

must be

None or a list of a length equal to the

value. If the

value is a list, the values are appended to each numeric stem in the plot.

Here, each base unit is broken into two stems and the stems are labeled

and

, for low and high.

Out[24]= | |

A number of options to the

Leaves option can be used to modify how leaves are computed and displayed.

| | |

"LeafDigits" | 1 | the number of digits to use for each leaf |

"LeafSpacing" | Automatic | the number of spaces between displayed leaves |

"LeafWrapping" | None | specifies when leaves should be wrapped to a new line |

"RoundLeaves" | True | whether data entries should be rounded before determining leaves |

Suboptions for all Leaves option values.

The

option specifies the number of digits beyond the stem to use in computing leaves. This is also the number of digits displayed for each leaf if leaves are displayed as

. The value must be a positive integer.

indicates the number of spaces to display between leaves.

can be set to a non-negative integer or

Automatic. With

Automatic, zero spaces are used when

, and one space is used otherwise.

specifies the number of leaves after which leaves should be wrapped to a new line.

can be any positive integer or

None, with

None indicating that leaves should not be wrapped to new lines.

specifies whether or not values should be rounded to the last leaf digit before computing leaves.

The following generates 100 numbers between 0 and 5.

This displays the data using two digits for leaves and including two spaces between leaves.

Out[26]= | |

Wrapping leaves to a new line can be useful if there is a large number of leaves for one or more stems, as is the case with this dataset.

Here the leaves are wrapped to a new line after 12 leaves, and row lines are inserted.

Out[27]= | |

If leaves are displayed as

, the symbol used as tally markers can also be specified.

| | |

"TallySymbol" | "X" | the symbol to use for each leaf |

Suboption for leaves.

The

option can be any string or symbol.

Here the leaves for

sldata4 are represented by checkmarks.

Out[28]= | |

From the previous display it is clear which stems contain more values than others. Including other features, such as counts and leaf wrapping, can be useful in determining the actual magnitudes of the leaf counts for each stem.

Wrapping leaves and including counts can make the plot easier to comprehend.

Out[29]= | |