# Connexions

You are here: Home » Content » Collaborative Statistics Using R » Stem and Leaf Graphs and Bar Graphs

### Recently Viewed

This feature requires Javascript to be enabled.

Inside Collection (Textbook):

Textbook by: Ananda Mahto. E-mail the author

# Stem and Leaf Graphs and Bar Graphs

Module by: Ananda Mahto. E-mail the author

Summary: This module introduces the use of stem-and-leaf graphs (stemplots), line graphs and bar graphs for describing a set of data visually.

One simple graph, the stem-and-leaf graph or stemplot, comes from the field of exploratory data analysis.It is a good choice when the data sets are small. To create the plot, divide each observation of data into a stem and a leaf. The leaf consists of one digit. For example, 23 has stem 2 and leaf 3. Four hundred thirty-two (432) has stem 43 and leaf 2. Five thousand four hundred thirty-two (5,432) has stem 543 and leaf 2. The decimal 9.3 has stem 9 and leaf 3. Write the stems in a vertical line from smallest the largest. Draw a vertical line to the right of the stems. Then write the leaves in increasing order next to their corresponding stem.

## Example 1

For Susan Dean's spring pre-calculus class, scores for the first exam were as follows (smallest to largest):

33, 42, 49, 49, 53, 55, 55, 61, 63, 67, 68, 68, 69, 69, 72, 73, 74, 78, 80, 83, 88, 88, 88, 90, 92, 94, 94, 94, 94, 96, 100

Table 1: Stem-and-Leaf Diagram
Stem Leaf
3 3
4 299
5 355
6 1378899
7 2348
8 03888
9 0244446
10 0

The stemplot shows that most scores fell in the 60s, 70s, 80s, and 90s. Eight out of the 31 scores or approximately 26% of the scores were in the 90's or 100, a fairly high number of As.

The stemplot is a quick way to graph and gives an exact picture of the data. You want to look for an overall pattern and any outliers. An outlier is an observation of data that does not fit the rest of the data. It is sometimes called an extreme value. When you graph an outlier, it will appear not to fit the pattern of the graph. Some outliers are due to mistakes (for example, writing down 50 instead of 500) while others may indicate that something unusual is happening. It takes some background information to explain outliers. In the example above, there were no outliers.

## Example 2

Create a stem plot using the data:

1.1, 1.5, 2.3, 2.5, 2.7, 3.2, 3.3, 3.3, 3.5, 3.8, 4.0, 4.2, 4.5, 4.5, 4.7, 4.8, 5.5, 5.6, 6.5, 6.7, 12.3

The data are the distance (in kilometers) from a home to the nearest supermarket.

### Problem 1

1. Are there any outliers?
2. Do the data seem to have any concentration of values?

#### Hint:

The leaves are to the right of the decimal.

#### Solution

The value 12.3 may be an outlier. Values appear to concentrate at 3 and 4 miles.

Table 2
Stem Leaf
1 1 5
2 3 5 7
3 3 3 3 5 8
4 0 2 5 5 7 8
5 5 6 6
6 5 7
7
8
9
10
11
12 3

## Stem and Leaf Plots in R

The stem() function in R is used to create stem and leaf plots. For most purposes, you do not need to pass on any other arguments; however, you may occasionally, need to use the scale argument to get a more usable stem and leaf plot. Notice that R tells you where the decimal is in its output so that you can easily figure out the original values.



exam.scores = c(33, 42, 49, 49, 53, 55, 55, 61, 63,
67, 68, 68, 69, 69, 72, 73, 74, 78, 80, 83, 88,
88, 88, 90, 92, 94, 94, 94, 94, 96, 100)
stem(exam.scores)
##
##   The decimal point is 1 digit(s) to the right of the |
##
##    3 | 3
##    4 | 299
##    5 | 355
##    6 | 1378899
##    7 | 2348
##    8 | 03888
##    9 | 0244446
##   10 | 0



Bar graphs consist of bars that are separated from each other. The bars can be rectangles or they can be be rectangular boxes and they can be vertical or horizontal. The bar graph shown in Example 4 uses the data of Example 3. Frequencies are represented by the the heights of the bars.

## Example 3

In a survey, 40 mothers were asked how many times per week a teenager must be reminded to do his/her chores. The results are shown in the table and the bar graph.

Table 3
Number of times teenager is reminded Frequency
02
15
28
314
77
54

## Bar Graphs in R

To create a bar graph in R, you need to use the barplot() function. There are several useful arguments for this function including:

• names.arg : An object representing the values to be placed below each bar (usually the x-axis).
• xlab : The title for your x-axis.
• ylab : The title for your y-axis.
• main : The title of your graph.


reminders = c(0, 1, 2, 3, 7, 5)
frequency = c(2, 5, 8, 14, 7, 4)
barplot(frequency, names.arg=reminders,
xlab="Number of reminders",
ylab="Frequency of responses",
main="Number of times each week
that a teenager is reminded to do chores")



The bar graph shown in Example 5 has age groups represented on the x-axis and proportions on the y-axis.

## Example 5

By the end of March 2009, in the United States Facebook had over 56 million users. The table shows the age groups, the number of users in each age group and the proportion (%) of users in each age group. Source: http://www.insidefacebook.com/2009/03/25/number-of-us-facebook-users-over-35-nearly-doubles-in-last-60-days/

Table 4
13 - 25 25,510,040 46%
26 - 44 23,123,900 41%
45 - 65 7,431,020 13%

## Glossary

Outlier:
An observation that does not fit the rest of the data.

## Content actions

### Give feedback:

#### Collection to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

#### Module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks