DEV Community

maxwizard01
maxwizard01

Posted on

How to plot stem and leaf in R-programming

Stem-and-leaf Charts

There are a range of graphical summaries of data. If the data set is relatively small, the stem-and-leaf diagram is
very useful for seeing the shape of the distribution and the values. It takes a little getting used to. The number on
the left of the bar is the stem, the number on the right the digit. You put them together to find the observation.
Suppose you have the box score of a basketball game and find the following points per game for players on both teams
21 13 16 23 14 12 14 13 22 10 10 20 16 28 21 14 14 18 22 15.
To create a stem and leaf chart is simple, all you need is the stem() function.
Let's try to solve the question above.
Codes>>

score=c(21, 13, 16, 23, 14, 12, 14, 13 ,22 1,20, 10, 20 ,16, 28 21,14,14,18,22,15)
stem(scores)
Enter fullscreen mode Exit fullscreen mode

Result>>

> score=c(21, 13, 16, 23, 14, 12, 14, 13 ,22,13,20, 10, 20 ,16, 28, 21,14,14,18,22,15)
> stem(score)

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

  1 | 023334444
  1 | 5668
  2 | 0011223
  2 | 8
Enter fullscreen mode Exit fullscreen mode

Can you see how easy it is?? let's try one more Example

Example2

Represent the following data in stem and leaf.
1,3, 6, 1,3,3, 4, 3, 3, 1, 3 ,5 ,1, 2, 1 ,4, 3, 2 ,3 ,1 ,1, 1 ,1, 4, 3, 1,5,5

Solution.
this is our codes below
Codes>>

data=c(1,3, 6, 1,3,3, 4, 3, 3, 1, 3 ,5 ,1, 2, 1 ,4, 3, 2 ,3 ,1 ,1, 1 ,1, 4, 3, 1,5,5)
stem(data)
Enter fullscreen mode Exit fullscreen mode

Result>>

data=c(1,3, 6, 1,3,3, 4, 3, 3, 1, 3 ,5 ,1, 2, 1 ,4, 3, 2 ,3 ,1 ,1, 1 ,1, 4, 3, 1,5,5)
> stem(data)

  The decimal point is at the |

  1 | 0000000000
  2 | 00
  3 | 000000000
  4 | 000
  5 | 000
  6 | 0
Enter fullscreen mode Exit fullscreen mode

Exercise
use the following marks to plot a stem and leaf.
46,47,60,40,54,29, 59, 50, 29, 59, 46, 51, 51, 50, 61,
32, 45, 42, 62, 62, 42, 37,28, 51, 41, 38,40, 41, 45, 59, 38,41,
45,34, 40, 59, 41,60, 54, 44, 56,53, 25 ,49,54, 58, 34, 60, 51, 25.

I hope this article satisfy your needs?? if so, then don't stop here try to read the next articles..

Top comments (0)