Here, we show how to make stem and leaf plots in R, and setting or adjusting the scale.

These are done with the stem() function.

See plots & charts for other plots and charts.

1 Create a Simple Stem and Leaf Plot in R

Enter the data by hand:

Stemdata = c(67, 72, 74, 62, 56, 66, 65, 59, 61, 69,
             74, 69, 66, 68, 58, 64, 66, 57, 68, 62)
Stemdata
 [1] 67 72 74 62 56 66 65 59 61 69 74 69 66 68 58 64 66 57 68 62

You can then create a simple stem and leaf plot with the stem() function:

The plot’s first line says, "the decimal point is 1 digit(s) to the right of the |" which means that since the first row is "5 | 6789", the lowest values are 56, 57, 58, and 59. Also, since the last row is "7 | 244", hence, the highest values are 72, 74, and 74.

stem(Stemdata)

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

  5 | 6789
  6 | 1224
  6 | 566678899
  7 | 244

Using a Data Object:

Using the airquality data from the "datasets" package with some sub-setting and filtering.

Sample rows from the airquality data:

airquality
    Ozone Solar.R Wind Temp Month Day
1      41     190  7.4   67     5   1
15     18      65 13.2   58     5  15
44     23     148  8.0   82     6  13
51     13     137 10.3   76     6  20
91     64     253  7.4   83     7  30
92     59     254  9.2   81     7  31
119    NA     153  5.7   88     8  27
150    NA     145 13.2   77     9  27
152    18     131  8.0   76     9  29
153    20     223 11.5   68     9  30

The plot’s first line says "the decimal point is at the |" which means that since the first row is "1 | 7", the lowest value is 1.7. Also, since the last row is "20 | 17", the highest values are 20.1, and 20.7.

stem(airquality$Wind)

  The decimal point is at the |

   1 | 7
   2 | 38
   3 | 4
   4 | 016666
   5 | 111777
   6 | 33333333999999999
   7 | 4444444444
   8 | 0000000000066666666
   9 | 2222222277777777777
  10 | 3333333333399999999
  11 | 555555555555555
  12 | 0000666
  13 | 2288888
  14 | 33333399999999
  15 | 555
  16 | 1666
  17 | 
  18 | 4
  19 | 
  20 | 17

2 Adjust the Scale of a Stem and Leaf Plot in R

In the plot below, notice that the stem has only even numbers. This is due to the high number of 10s value (0 to 33, as the lowest number is 7 and the highest is 334).

With the plot’s first line saying "the decimal point is 1 digit(s) to the right of the |" and the first row being "0 | 78349", the lowest values are 7, 8, then 13, 14, and 19. Also, since the last row is "32 | 022324", the highest values are 320, 322, 322, 323, 332, and 334.

stem(airquality$Solar.R)

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

   0 | 78349
   2 | 04457167
   4 | 478919
   6 | 456178
   8 | 123122589
  10 | 1258
  12 | 0771577899
  14 | 589037
  16 | 7555
  18 | 3678900112347
  20 | 137235
  22 | 0002333459066778888
  24 | 24800223455689999
  26 | 04467923344569
  28 | 4567011459
  30 | 734
  32 | 022324

To increase the number of stems, use the argument "scale = 2" to adjust the scale of the plot.

The decimal point is still as above. Given the new plot’s first row is "0 | 78", the lowest values are 7, and 8. Also, since the last row is "33 | 24", the highest values are 332, and 334.

stem(airquality$Solar.R, scale = 2)

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

   0 | 78
   1 | 349
   2 | 04457
   3 | 167
   4 | 4789
   5 | 19
   6 | 456
   7 | 178
   8 | 123
   9 | 122589
  10 | 1
  11 | 258
  12 | 077
  13 | 1577899
  14 | 589
  15 | 037
  16 | 7
  17 | 555
  18 | 36789
  19 | 00112347
  20 | 137
  21 | 235
  22 | 0002333459
  23 | 066778888
  24 | 248
  25 | 00223455689999
  26 | 044679
  27 | 23344569
  28 | 4567
  29 | 011459
  30 | 7
  31 | 34
  32 | 0223
  33 | 24

Copyright © 2020 - 2024. All Rights Reserved by Stats Codes