1
2
3
4
5
#

R: Stem-and-leaf

I. Basic Stem-and-leaf
We will construct a stem-and-leaf graph of the dist variable from the cars dataset. The following code gives us a chance to see the first 6 rows of the cars dataset.
> ### Lets look at first 6 rows of cars data set
speed dist
1     4    2
2     4   10
3     7    4
4     7   22
5     8   16
6     9   10

Next, we are going to create a new d variable that will represent the distance data from the cars dataset. Then we will use the stem() function to construct a basic stem-and-leaf plot of the d variable.

> # Create new variable d
> d = cars\$dist
>
> # Construct stem-and-leaf of d
> stem(d)

The decimal point is 1 digit(s) to the right of the |

0 | 24004678
2 | 002466668822244466
4 | 002668024466
6 | 046806
8 | 04523
10 |
12 | 0

II. scale Parameter
The scale parameter can be used to expand the scale of the plot. A value of scale=2 will split the stems and cause the output to be roughly twice as long as the default.
> stem(d, scale = 2)

The decimal point is 1 digit(s) to the right of the |

0 | 24
1 | 004678
2 | 0024666688
3 | 22244466
4 | 002668
5 | 024466
6 | 0468
7 | 06
8 | 045
9 | 23
10 |
11 |
12 | 0

A value of scale=4 will split the stems and cause the output to be roughly four times as long as the default.

> stem(d, scale = 4)

The decimal point is 1 digit(s) to the right of the |

0 | 24
0 |
1 | 004
1 | 678
2 | 0024
2 | 666688
3 | 222444
3 | 66
4 | 002
4 | 668
5 | 0244
5 | 66
6 | 04
6 | 68
7 | 0
7 | 6
8 | 04
8 | 5
9 | 23
9 |
10 |
10 |
11 |
11 |
12 | 0