Compute and display a stem and leaf plot of the vector x.
The input x should be a vector of integers. Any non-integer values
will be converted to integer by x = fix (x)
. By default
each element of x will be plotted with the last digit of the element
as a leaf value and the remaining digits as the stem. For example, 123
will be plotted with the stem ‘12’ and the leaf ‘3’. The second
argument, caption, should be a character array which provides a
description of the data. It is included as a heading for the output.
The optional input stem_sz sets the width of each stem.
The stem width is determined by 10^(stem_sz + 1)
.
The default stem width is 10.
The output of stemleaf
is composed of two parts: a
"Fenced Letter Display," followed by the stem-and-leaf plot itself.
The Fenced Letter Display is described in Exploratory Data Analysis.
Briefly, the entries are as shown:
Fenced Letter Display #% nx|___________________ nx = numel (x) M% mi| md | mi median index, md median H% hi|hl hu|hs hi lower hinge index, hl,hu hinges, 1 |x(1) x(nx)| hs h_spreadx(1), x(nx) first _______ and last data value. ______|step |_______ step 1.5*h_spread f|ifl ifh| inner fence, lower and higher |nfl nfh| no.\ of data points within fences F|ofl ofh| outer fence, lower and higher |nFl nFh| no.\ of data points outside outer fences
The stem-and-leaf plot shows on each line the stem value followed by the string made up of the leaf digits. If the stem_sz is not 1 the successive leaf values are separated by ",".
With no return argument, the plot is immediately displayed. If an output argument is provided, the plot is returned as an array of strings.
The leaf digits are not sorted. If sorted leaf values are desired, use
xs = sort (x)
before calling stemleaf (xs)
.
The stem and leaf plot and associated displays are described in: Chapter 3, Exploratory Data Analysis by J. W. Tukey, Addison-Wesley, 1977.
See also: hist, printd.
The following code
## Unsorted plot: x = [-22 12 -28 52 39 -2 12 10 11 11 42 38 44 18 44]; stemleaf (x, "Unsorted plot");
Produces the following output
Data: Unsorted plot Fenced Letter Display # 15|___________________ M 8| 12 | H 4| 10 42| 32 1 | -28 52| _______ ______| 48|_______ f| -38 90| | 0 0| out F| -86 138| | 0 0| far -2 | 28 : -0 | 2 0 | 1 | 220118 : 3 | 98 4 | 244 5 | 2
The following code
## Sorted leaves: x = [-22 12 -28 52 39 -2 12 10 11 11 42 38 44 18 44]; y = sort (x); stemleaf (y, "Sorted leaves");
Produces the following output
Data: Sorted leaves Fenced Letter Display # 15|___________________ M 8| 12 | H 4| 10 42| 32 1 | -28 52| _______ ______| 48|_______ f| -38 90| | 0 0| out F| -86 138| | 0 0| far -2 | 82 : -0 | 2 0 | 1 | 011228 : 3 | 89 4 | 244 5 | 2
The following code
## Sorted leaves (large dataset): x = [-22 12 -28 52 39 -2 12 10 11 11 42 38 44 18 44 37 113 124 37 48 ... 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 ... 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 ... 121 58 114 126 53 114 96 25 109 7 31 141 46 -13 71 43 117 116 27 7 ... 68 40 31 115 124 42 128 52 71 118 117 38 27 106 33 117 116 111 40 ... 119 47 105 57 122 109 124 115 43 120 43 27 27 18 28 48 125 107 114 ... 34 133 45 120 30 127 31 116 146 21 23 30 10 20 21 30 0 100 110 1 20 ... 0]; y = sort (x); stemleaf (y, "Sorted leaves (large dataset)");
Produces the following output
Data: Sorted leaves (large dataset) Fenced Letter Display #138|___________________ M 69| 52 | H 35| 30 116| 86 1 | -28 146| _______ ______| 129|_______ f| -99 245| | 0 0| out F| -228 374| | 0 0| far -2 | 82 -1 | 3 -0 | 2 0 | 00177 1 | 00112288 2 | 001133577777899 3 | 000111123456777889 4 | 00122233344456788 5 | 223788 6 | 138 7 | 11 : 9 | 69 10 | 04555567999 11 | 0133344455566667777899 12 | 0011223444555677788 13 | 1239 14 | 16
The following code
## Gaussian leaves: x = fix (30 * randn (300,1)); stemleaf (x, "Gaussian leaves");
Produces the following output
Data: Gaussian leaves Fenced Letter Display #300|___________________ M150| 1 | H 75| -19 19| 38 1 | -92 78| _______ ______| 57|_______ f| -76 76| | 2 1| out F| -133 133| | 0 0| far -9 | 22 : -6 | 01765 -5 | 930037 -4 | 9495329170307 -3 | 187801881373222463588732 -2 | 394816370271932932133795 -1 | 303737475249130580023686991137 -0 | 22015238467513036609471026827733069854084 0 | 4745500592677496631653451247179621302 1 | 359449556026915394663604910101030134019558685774 2 | 7828152122925697471600554842 3 | 00946071301909031484490 4 | 321991787 5 | 3830 6 | 082 7 | 834
Package: octave