In[]:=
(*loadthe"StatisticalPlots"packagewhichcontainsthedefinitionsofvariousstatisticalplotssuchasStemLeafPlot,PairwiseScatterPlot,etc.*)​​<<"StatisticalPlots`";
For the first few examples in this notebook, we shall make use of the schoolkids dataset provided below:
In[]:=
schoolkids=
Name
Gender
Age
Height
Weight
1
Agatha
F
12
57
83.7
2
Allan
M
14
68.9
111.5
3
Ann
F
11
51.3
50.5
4
Betty
F
13
65
98.2
5
Cindy
N
13
61.9
100.3
6
George
M
15
67
133
7
Ginger
F
12
59.4
84
8
Harry
M
14
64.2
103
9
Jamie
M
13
57.6
93.5
10
Jan
F
11
57
83
11
Johnny
N
13
62
83.5
12
Julie
F
13
63.2
113
13
Leonore
F
12
56.7
77
14
Liz
F
14
64
90.2
15
Michelle
F
15
66
111
16
Mildred
F
11
51.6
54
17
Paul
M
16
71
149
18
Roscoe
M
12
64.2
126.5
19
Steven
M
13
61
86
20
Tim
M
11
55
52
;
In[]:=
(*extractsimplevaluelistsfromthedatasetforheightandweigtcolumns*)​​heightList=Values[Normal[schoolkids[All,4]]];​​weightList=Values[Normal[schoolkids[All,5]]];

Stem and Leaf Plot

In[]:=
StemLeafPlot[heightList]
Out[]=
Stem
Leaves
5
12577789
6
12234445679
7
1
Stem units: 10

Pie Charts

In[]:=
ndxAgeVar=3;​​age11=Select[schoolkids,#[[ndxAgeVar]]11&];​​age12=Select[schoolkids,#[[ndxAgeVar]]12&];​​age13=Select[schoolkids,#[[ndxAgeVar]]13&];​​age14=Select[schoolkids,#[[ndxAgeVar]]14&];​​age15orOlder=Select[schoolkids,#[[ndxAgeVar]]>=15&];​​ageLists={age11,age12,age13,age14,age15orOlder};
In[]:=
ageLists
Out[]=

Name
Gender
Age
Height
Weight
3
Ann
F
11
51.3
50.5
10
Jan
F
11
57
83
16
Mildred
F
11
51.6
54
20
Tim
M
11
55
52
,
Name
Gender
Age
Height
Weight
1
Agatha
F
12
57
83.7
7
Ginger
F
12
59.4
84
13
Leonore
F
12
56.7
77
18
Roscoe
M
12
64.2
126.5
,
Name
Gender
Age
Height
Weight
4
Betty
F
13
65
98.2
5
Cindy
N
13
61.9
100.3
9
Jamie
M
13
57.6
93.5
11
Johnny
N
13
62
83.5
12
Julie
F
13
63.2
113
19
Steven
M
13
61
86
,
Name
Gender
Age
Height
Weight
2
Allan
M
14
68.9
111.5
8
Harry
M
14
64.2
103
14
Liz
F
14
64
90.2
,
Name
Gender
Age
Height
Weight
6
George
M
15
67
133
15
Michelle
F
15
66
111
17
Paul
M
16
71
149

In[]:=
ageListWithLabels=Table[Labeled[Length[ageLists[[i]]],"age"<>If[i<5,ToString[10+i],"15+"]],{i,1,Length[ageLists]}];
In[]:=
PieChart[ageListWithLabels​​,PlotLabel"Pie Chart for age"]
Out[]=

Box and Whisker Plots

In[]:=
(*BoxWhiskerchartwithOutliersandMeanDiamondoptions*)​​BoxWhiskerChart[heightList,{"Outliers",{"MeanDiamond"}},PlotLabel"Box Whisker Chart for Height"]
Out[]=
In[]:=
(*BoxWhiskerchartforHeightandWeight*)​​BoxWhiskerChart[{heightList,weightList},{"Outliers",{"MeanDiamond"}}​​,ChartLabels{"height","weight"}​​,BarOriginLeft​​,PlotLabel"Box Whisker Charts for Height and Weight"]
Out[]=

Histograms

In[]:=
histPlot0=Histogram[heightList,PlotLabel"Histogram for Height"]

PDF Plots

Scatter Plots

We could have constructed the same list of data pairs by combining the heightList and weightList lists we defined at the outset:
We use Mathematica’s ListPlot function to render the scatter plot.
In the following example, we create a scatterplot with tooltips. When you hover your cursor over a point in the scatter plot, you will see the name of the child associated with that point appear in a tooltip.

Contour Plot (aka ListPlot3D)

In this example, we use the lake dataset provided by SAS Institute. We converted the lake.csv file provided by SAS into a Mathematica dataset. You can find other SAS datasets at this link:
​https://support.sas.com/documentation/onlinedoc/viya/examples.htm
We shall use the ListPlot3D function to create a rotatable contour plot. The ListPlot3D function is just one of the many functions that allow you to dynamically interact with the plot itself. You can rotate the image using your mouse. Click on the plot with your mouse button (on Windows, click with your left mouse button). While you continue to hold down the button, move your mouse left to right and up and down. You can rotate the plot in any direction you desire.

Dendrogram

The povertyData dataset is based on Rouncefield, “The Statistics of Poverty and Inequality” (1995), Journal of Statistics Education v .3, n .2 .
Description: Birth rates, death rates, and infant death rates for 33 countries in millions per country.

Array Plot (aka Cell Plot)

The histlevels dataset below is based on Cole, J.W.L. and Grizzle, J.E. (1966), “Applications of Multivariate Analysis of Variance to Repeated Measures Experiments,” Biometrics, 22, 810 -828.
Description: Sixteen dogs are randomly assigned to four groups. (One animal is removed from the analysis due to a missing value for one dependent variable.) The dogs receive either morphine or trimethaphan. Histamine levels are measured at 4 different times.
The only problem with the plot is that we would like to display labels along the x axis. We can do this using the FrameTicks option.
Suppose we want to rotate the labels on the x axis. We can do this as follows.

Pairwise Scatter Plot

The PairwiseScatterPlot function does not operate on datasets. Therefore, the input we provide to the function must be an ordinary list.
The only problem with the plot is that the labels on the bottom need to be rotated. We remedy this problem as follows.
The PairwiseScatterPlot function assumes that the tick values on the y axis are in descending order. I.e., tick value at top of y axis > tick value at bottom of y axis. Thus, when we make ticks for y axis, we reverse the order of the solvent names when we call our helper function. This puts “1-Octanol” at the top of the y axis and Hexane at the bottom of the y axis (the origin) which is the order in which we want them to appear on the y axis.