# 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 charts, and pie charts are also commonly used in statistical applications, and are included in the Wolfram Language kernel.

ParetoPlot[data] | create a Pareto plot from the data |

PairwiseScatterPlot[matrix] | create a pairs scatter plot from multivariate data |

StemLeafPlot[data] | create a stem‐and‐leaf plot from a list of data |

Basic statistics‐related plots.

## 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 cat_{i} with given frequencies freq_{i} |

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.

If you have data where the frequencies are precomputed, you can plot it directly by providing {category,frequency} pairs instead of the raw data to ParetoPlot.

option name | default value | |

BarOrigin | Bottom | origin placement for bars |

BarSpacing | Automatic | fractional spacing between bars |

ChartElementFunction | Automatic | how to generate raw graphics for bars |

ChartElements | Automatic | graphics to use in each of the bars |

ChartLabels | Automatic | labels for bars |

ChartStyle | Automatic | style for bars |

ColorFunction | Automatic | how to color bars |

ColorFunctionScaling | True | whether to normalize arguments to ColorFunction |

LabelingFunction | Automatic | how to label bars |

PlotStyle | Automatic | style for the line |

PlotMarkers | Automatic | markers for the points |

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 Bar and Chart 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.

## 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 |

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.

option name | default value | |

DataRanges | All | range limits on the data |

DataLabels | None | labels for the columns |

DataTicks | None | tick specifications for the columns |

DataSpacing | 0 | space to place between subgraphs |

PlotDirection | {Right,Down} | direction in which scatter plots are generated |

PlotStyle | Automatic | styles for the subgraphs |

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 {min,max} 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 ^{th} row and j ^{th} 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 -> {0,-2}. An interesting effect can be derived by setting this option to -1, where all the subgraphs are overlaid.

In addition, all of the usual Graphics options are accepted.

## 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 |

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.

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

option name | default value | |

StemExponent | Automatic | stem units given as an integer power of 10 |

Leaves | "Digits" | how leaves are represented |

ColumnLabels | Automatic | labels for the columns of the plot |

IncludeEmptyStems | False | whether stems without leaves should be displayed |

IncludeStemUnits | True | whether stem units should be included in the plot |

IncludeStemCounts | Automatic | whether to include a column of counts along with the leaves |

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 "Digits", "Tallies", or None. With Leaves->"Tallies", 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 Stem, leaf columns are labeled Leaves, and count columns are labeled Counts.

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 Leaves option is set to None.

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.

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

option name | default value | |

"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 "UnitDivisions" option specifies the number of stems a base unit should be divided into. The value of "UnitDivisions" must be a positive integer.

Alternate labeling of subdivisions can be specified via the "DivisionLabels" option. The value of "DivisionLabels" must be None or a list of a length equal to the "UnitDivisions" value. If the "DivisionLabels" value is a list, the values are appended to each numeric stem in the plot.

A number of options to the Leaves option can be used to modify how leaves are computed and displayed.

option name | default value | |

"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 "LeafDigits" 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 "Digits". The value must be a positive integer.

"LeafSpacing" indicates the number of spaces to display between leaves. "LeafSpacing" can be set to a non-negative integer or Automatic. With "LeafSpacing"->Automatic, zero spaces are used when "LeafDigits"->1, and one space is used otherwise.

"LeafWrapping" specifies the number of leaves after which leaves should be wrapped to a new line. "LeafWrapping" can be any positive integer or None, with None indicating that leaves should not be wrapped to new lines.

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

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.

If leaves are displayed as "Tallies", the symbol used as tally markers can also be specified.

Suboption for "Tallies" leaves.

The "TallySymbol" option can be any string or symbol.

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.