maths.freeStatistics & Probability › 8. Statistics › Visualizing Data

Visualizing Data

Create charts and graphs to appropriately represent data.

Learning Objectives

After completing this section, you should be able to:

  1. Create charts and graphs to appropriately represent data.
  2. Interpret visual representations of data.
  3. Determine misleading components in data displayed visually.

Visualizing Categorical Data

If the data we’re visualizing is categorical, then we want a quick way to represent graphically the relative numbers of units that fall in each category. When we created the frequency distributions in the last section, all we did was count the number of units in each category and record that number (this was the frequency of that category). Frequencies are nice when we’re organizing and summarizing data; they’re easy to compute, and they’re always whole numbers. But they can be difficult to understand for an outsider who’s being introduced to your data.

Let’s consider a quick example. Suppose you surveyed some people and asked for their favorite color. You communicated your results using a frequency distribution. Jerry is interested in data on favorite colors, so he reads your frequency distribution. The first row shows that twelve people indicated green was their favorite color. However, Jerry has no way of knowing if that’s a lot of people without knowing how many people total took your survey. Twelve is a pretty significant number if only twenty-five people took the survey, but it’s next to nothing if you recorded a thousand responses. For that reason, we will often summarize categorical data not with frequencies, but with proportions. The proportion of data that fall into a particular category is computed by dividing the frequency for that category by the total number of units in the data.

\(Proportion of a category=\frac{Category frequency}{Total number of data units}\)

Proportions can be expressed as fractions, decimals, or percentages.

Now that we can compute proportions, let’s turn to visualizations. There are two primary visualizations that we’ll use for categorical data: bar charts and pie charts. Both of these data representations work on the same principle: If proportions are represented as areas, then it’s easy to compare two proportions by assessing the corresponding areas. Let’s look at bar charts first.

Condensed — the full section is in OpenStax Contemporary Mathematics.

Visualizing Quantitative Data

There are several good ways to visualize quantitative data. In this section, we’ll talk about two types: stem-and-leaf plots and histograms.

Sometimes we have quantitative data where each value is labeled according to the source of the data. For example, in the Your Turn above, you looked at in-state tuition data. Every value you used to create that histogram was associated with a school; the schools are the labels. In YOUR TURN 8.11, you found a histogram of the wins of every Major League Baseball team in 2019. Each of those win totals had a label: the team. If we’re interested in visualizing differences among the different teams, or schools, or whatever the labels are, we create a different version of the bar graph known as a bar chart for labeled data.

These graphs are made in Google Sheets in exactly the same way as regular bar graphs. The only change is that the vertical axis will be labeled with the units for your quantitative data instead of just “Frequency.”

Building a Bar Chart for Labeled Data

Try it.

The following table shows the gross domestic product (GDP) for the United States for the years 2010 to 2019:

YearGDP (in $ trillions)YearGDP (in $ trillions)
201014.992201518.225
201115.543201618.715
201216.197201719.519
201316.785201820.580
201417.527201921.433

Construct a histogram that represents these data.

Solution

In this case, the years are the labels, and the data we are interested in are the GDP numbers. Once you have the table above (including the labels) entered into a spreadsheet, click and drag to select the full table. Then, in the “Insert” menu, click “Chart.” The result may not be a bar chart; if it’s not, select “Column chart” in the drop-down menu “Chart type” in the Chart Editor. If you want, you can edit things like the chart title in the “Customize” tab in the Chart Editor.

Condensed — the full section is in OpenStax Contemporary Mathematics.

Misleading Graphs

Graphical representations of data can be manipulated in ways that intentionally mislead the reader. There are two primary ways this can be done: by manipulating the scales on the axes and by manipulating or misrepresenting areas of bars. Let’s look at some examples of these.

Condensed — the full section is in OpenStax Contemporary Mathematics.

Key Concepts

  • Categorical data can be visualized using pie charts or bar charts; quantitative data can be visualized using stem-and-leaf plots or histograms.
  • Areas in pie charts and bar charts represent proportions of the data falling into a particular category, while areas in histograms represent proportions of the data that fall into a given range of data values (or “bins”). Stem-and-leaf plots are visual representations of entire datasets.
  • By manipulating the axes, changing widths of bars, or making bad choices for bins, we can create data visualizations that misrepresent the distribution of data.

Videos

  • Make a Simple Bar Graph in Google Sheets
  • Create Pie Charts Using Google Sheets
  • Make a Histogram Using Google Sheets
  • How to Spot a Misleading Graph

Practice (10)

Try each one on paper first. Reveal the answer to check; verified ones can be opened in the solver for every step.

  1. Recall , in which a teacher recorded the responses on the first question of a multiple choice quiz, with five possible responses (A, B, C, D, and E). The raw data was as follows:

    AACABBAEACAAAC
    EABAACABEEAACC

    We computed a frequency distribution that looked like this:

    Response to First QuestionFrequency
    A14
    B4
    C6
    D0
    E4

    \(Proportion of a category=Category frequency/Total number of data units\)

    Now, let's compute the proportions for each category.

    Die Antwort aufzeigen

    Step 1: In order to compute a proportion, we need the frequency (which we have in the table above) and the total number of units that are represented in our data. We can find that by adding up the frequencies from all the categories: \(14+4+6+0+4=28\).

    Step 2: To find the proportions, we divide the frequency by the total. For the first category (“A”), the proportion is \(\frac{14}{28}=\frac{1}{2}=0.5=50\%.\) We can compute the other proportions similarly, filling in the rest of the table:

    Response to First QuestionFrequencyProportion
    A14\[\frac{14}{28}=50\%\]
    B4\[\frac{4}{28}=14.3\%\]
    C6\[\frac{6}{28}=21.4\%\]
    D0\[\frac{0}{28}=0\%\]
    E4\[\frac{4}{28}=14.3\%\]

    Step 3: Check your work: If you add up your proportions, you should get 1 (if you’re using fractions or decimals) or 100% (if you’re using percentages). In this case, \(50\%+14.3\%+21.4\%+0\%+14.3\%=100\%.\)

  2. In , we computed the following proportions:

    Response to First QuestionFrequencyProportion
    A1450%
    B414.3%
    C621.4%
    D00%
    E414.3%
    Draw a bar chart to visualize this frequency distribution.

    Die Antwort aufzeigen

    Step 1: To start, we’ll draw axes with the origin (the point where the axes meet) at the bottom left:

    Step 2: Next, we’ll place our categories evenly spaced along the bottom of the horizontal axis. The order doesn’t really matter, but if the categories have some sort of natural order (like in this case, where the responses are labeled A to E), it’s best to maintain that order. We'll also label the horizontal axis:

    Step 3: Now, we have a decision to make: Will we use frequencies to define the height of our rectangles, or will we use proportions? Let’s try it both ways. First, let’s use frequencies. Notice that our frequencies run from zero to 14; this will correspond to the scale we put on the vertical axis. If we put a tick mark for every whole number between 0 and 14, the result will be pretty crowded; let’s instead put a mark on the multiples of 3 or 5:

    Step 4: Now, let’s draw in the first rectangle. The frequency associated with “A” is 14. So we’ll go to 14 on the vertical axis, and place a mark at that height above the “A” label:

    Step 5: Then, draw vertical lines straight down from the edges of your mark to make a rectangle:

    Step 6: Finally, we can build the rest of the rectangles, making sure that the bases all have the same length of the base = width of the rectangle, and the rectangles don’t touch. Notice that, since the frequency for “D” is zero, that category has no rectangle (but we’ll leave a space there so the reader can see that there is a category with frequency zero). Here’s the result:

    Step 7: That’s it! Now, let’s use proportions instead of frequencies. We'll label the vertical axis with evenly spaced numbers that run the full range of the percentages in our table: 0% to 50%. We can divide that into five equal parts (so that each has width 10%), and use that to label our vertical axis:

    Step 8: Then, we can fill in the rectangles just as we did before. The height of the “A” rectangle is 50%, the “B” rectangle goes up to 14.3%, “C” goes to 21.4%, there is no rectangle for “D” (since its proportion is 0%), and the “E” rectangle also goes up to 14.3%:

    Step 9: Notice that the rectangles are basically identical in our two final bar charts. That’s no coincidence! Bar charts that use proportions and those that use frequencies will always look identical (which is why it doesn’t really matter much which option you choose). Here’s why: look at the bars for “B” and “C”. The frequencies for these are 4 and 6 respectively. Notice that 6 is 50% bigger than 4 (since \(6=1.5\times 4\)), which means that the “C” bar will be 50% higher than the “B” bar. Now look at the same bars using proportions: since \(21.4\%=1.5\times 14.3\%\), the bar for “C” will be 50% higher than the bar for “B.” The same relationships hold for the other bars, too.

  3. The bar graph shown gives data on 2020 model year cars available in the United States. Analyze the graph to answer the following questions.

    1. What proportion of available cars were sports cars?
    2. What proportion of available cars were sedans?
    3. Which categories of cars each made up less than 5% of the models available?

    Die Antwort aufzeigen

    1. The bar for sports cars goes up to 10%, so the proportion of models that are considered sports cars is 10%.
    2. The bar corresponding to sedan goes up past 30% but not quite to 35%. It looks like the proportion we want is between 33% and 34%.
    3. We’re looking for the bars that don’t make it all the way to the 5% line. Those categories are hatchback and wagon.

  4. Use the data that follows to generate a pie chart.

    TypePercentTypePercent
    SUV43.6%Minivan5.5%
    Sedan33.6%Hatchback3.6%
    Sports10.0%Wagon3.6%
    Die Antwort aufzeigen

    First, enter the chart above into a new sheet in Google Sheets. Next, click and drag to select the full table (including the header row). Click on the “Insert” menu, then select “Chart.” The result may be a pie chart by default; if it isn’t, you can change it to a pie chart using the “Chart type” drop-down menu in the Chart Editor.

    You can choose to use a legend to identify the categories, as well as label the slices with the relevant percentages.

  5. A collector of trading cards records the sale prices (in dollars) of a particular card on an online auction site, and puts the results in a stem-and-leaf plot:

    05 8 9
    10 0 0 3 4 4 5 5 5 5 6 9 9
    20 0 0 0 5 5 9 9
    30 0 0 5 5
    40 0 5
    5
    60

    Answer the following questions about the data:

    1. How many prices are represented?
    2. What prices represent the five most expensive cards? The five least expensive?
    3. What is the full set of data?
    Die Antwort aufzeigen

    1. Each leaf (the numbers on the right side of the bar) represents one data value. So, on the first row (which looks like 0 | 5 8 9), there are three data values (one for each leaf: 5, 8, and 9). The next row has thirteen leaves, then eight, five, three, zero, and one. Adding those up, we get \(3+13+8+5+3+0+1=33\) data points or prices.
    2. The most expensive card is the last one listed. Its stem is 6 and its leaf is 0, so the price is $60. There are no leaves associated with the 5 stem, so there were no cards sold for $50 to $59. The next most expensive cards are then on the 4 stem: $45, $40, and $40 (remember, repeated leaves mean repeated values in the dataset). So, we have our four most expensive cards. The fifth would be on the next stem up. The biggest leaf on the 3 stem is a 5, so the fifth-most expensive card sold for $35.
      As for the five least-expensive cards, the smallest stem is 0, with leaves 5, 8, and 9. So, the three least expensive cards sold for $5, $8, and $9 (notice that we don’t write down that leading 0 from the stem in the tens place). The next two least-expensive cards will be the two smallest leaves on the next stem: $10 and $10.
    3. The full list of data is: 5, 8, 9, 10, 10, 10, 13, 14, 14, 15, 15, 15, 15, 16, 19, 19, 20, 20, 20, 24, 25, 25, 29, 29, 30, 30, 30, 35, 35, 40, 40, 45, 60.

  6. An entomologist studying crickets recorded the number of times different crickets (of differing species, genders, etc.) chirped in a one-minute span. The raw data are as follows:

    89978210284999310312091
    11510589109107891048210692
    1011091161031009185104104106

    Construct a stem-and-leaf plot to visualize these results.

    Die Antwort aufzeigen

    Step 1: Before we can create the plot, we need to sort the data in order from smallest to largest:

    82828485898989919192
    939799100101102103103104104
    104105106106107109109115116120

    Step 2: Next, we identify the stems. To do that, we cut off the final digit of each number, which leaves us with stems of 8, 9, 10, 11, and 12. Arrange the stems vertically, and add the bar to separate these from the leaves:

    8
    9
    10
    11
    12

    Step 3: Write down the leaves on the right side of the bar, giving just the final digit (that we cut off to make the stems) of each data value. List these in order, and make sure they line up vertically:

    82 2 4 5 9 9 9
    91 1 2 3 7 9
    100 1 3 3 4 4 4 5 6 6 7 9 9
    115 6
    120
  7. In , we built a stem-and-leaf plot for the number of chirps made by crickets in one minute. Here are the raw data that we used then:

    8997821028499
    1151058910910789
    10110911610310091
    931031209185104
    1048210692104106

    Construct a histogram to visualize these results.

    Die Antwort aufzeigen

    Step 1: Add data to bins. Histograms are built on binned frequency distributions, so we’ll make that first. Luckily, the stem-and-leaf plot we made earlier can help us do this much more quickly:

    82 2 4 5 9 9 9
    91 1 2 3 7 9
    100 1 2 3 3 4 4 4 5 6 6 7 9 9
    115 6
    120

    If we’re using bins of width 10, we can compute the frequencies by counting the numbers of leaves associated with the corresponding stem:

    BinFrequency
    80-897
    90-996
    100-10914
    110-1192
    120-1291

    (Note that, when we made binned frequency diagrams in the last module, we noted that if the biggest data value was right on the border between two bins, it was OK to lump it in with the lower bin. That’s not recommended when building histograms, so the data value 120 is all alone in the 120-129 bin.)

    Step 2: Create the axes. On the horizontal axis, start labeling with the lower end of the first bin (in this case, 80), and go up to the higher end of the last bin (120). Mark off the other bin boundaries, making sure they’re all evenly spaced. On the vertical axis, start with zero and go up at least to the greatest frequency you see in your bins (14 in this example), making sure that the labels you make are evenly spaced and that the difference between those numbers is the same. Let’s count off our vertical axis by threes:

    Step 3: Draw in the bars. Remember that the bars of a histogram touch, and that the heights are determined by the frequency. So, the first bar will cover 80 to 90 on the horizontal axis, and have a height of 7:

    Now, we can fill in the others:

    Step 4: Let’s compare the histogram we just created to the stem-and-leaf plot we made earlier:

    Notice that the leaves on the rotated stem-and-leaf plot match the bars on our histogram! We can view stem-and-leaf plots as sideways histograms. But, as we’ll see soon, we can do much more with histograms.

  8. The data in “AvgSAT” contains the average SAT score for students attending every institution of higher learning in the US for which data is available. Create a histogram in Google Sheets of the average SAT scores. Use bins of width 50. Are the data uniformly distributed, symmetric, left-skewed, or right-skewed?

    Die Antwort aufzeigen

    Using the procedure described in the video above, we get this:

    The data are fairly symmetric, but slightly right-skewed.

  9. The following table shows the gross domestic product (GDP) for the United States for the years 2010 to 2019:

    YearGDP (in $ trillions)YearGDP (in $ trillions)
    201014.992201518.225
    201115.543201618.715
    201216.197201719.519
    201316.785201820.580
    201417.527201921.433

    Construct a histogram that represents these data.

    Die Antwort aufzeigen

    In this case, the years are the labels, and the data we are interested in are the GDP numbers. Once you have the table above (including the labels) entered into a spreadsheet, click and drag to select the full table. Then, in the “Insert” menu, click “Chart.” The result may not be a bar chart; if it’s not, select “Column chart” in the drop-down menu “Chart type” in the Chart Editor. If you want, you can edit things like the chart title in the “Customize” tab in the Chart Editor.

  10. The table below shows the teams, and their payrolls, in the English Premier League, the top soccer organization in the United Kingdom.

    TeamSalary (£1,000,000s)TeamSalary (£1,000,000s)
    Manchester United F.C.175.7Newcastle United F.C.56.9
    Manchester City F.C.136.5Aston Villa F.C.52.3
    Chelsea F.C.132.8Fulham F.C.52.1
    Arsenal F.C.130.7Southampton F.C.49.6
    Tottenham Hotspur F.C.129.2Wolverhampton Wanderers F.C.49.5
    Liverpool F.C.118.6Brighton & Hove Albion43.7
    Crystal Palace85.0Burnley F.C.35.5
    Everton F.C.82.5West Bromwich Albion F.C.23.8
    Leicester City73.7Leeds United F.C.22.5
    West Ham United F.C.69.2Sheffield United F.C.19.7

    How might someone present this data in a misleading way?

    Die Antwort aufzeigen

    Step 1: Let’s focus on the top five teams. Here’s a bar chart of their payrolls:

    Step 2: Now, here’s another bar chart visualizing exactly the same data:

    Step 3: You should notice that despite using the same data, these two graphs look strikingly different. In the second graph, the gap between Manchester United and the other four teams looks significantly larger than in the first graph. The scale on the vertical axis has been manipulated here. The first graph's axis starts at zero, while the lowest value on the second graph's axis is 120. This trick has a strong impact on the viewer’s perception of the data.

    Step 4: To further emphasize the difference this creates in our perception, let's look at that data again, but this time using graphics instead of colored areas on our bar graph.

    This graph uses an image of a £10 banknote in place of the bars. Using an image that evokes the context of the data in place of a standard, “boring” bar is a common tool that people use when creating infographics. However, this is generally not a good practice because it distorts the data. Notice that our “bars” (the banknotes) are just as tall here as they were in the previous figure. But, to maintain the right proportions, the widths had to be adjusted as well, which changes the area (height × width) of each bar. A key point is that when looking at rectangles, the human eye tends to process areas more easily than heights.

    Step 5: Now, let’s look at all 20 teams. This histogram indicates that the data are right-skewed, with the highest number of teams having a payroll between £40 million and £80 million:

    Step 6: Now let's view this same data in another chart:

    Step 7: Even though this chart uses the same data, the skew seems to be reversed. Why? Well, even though this graph looks like a histogram, it isn’t. Look closely at the labels on the horizontal axis; they don't correspond to spots on the axis, but instead provide a range, meaning this is a bar graph based on a binned frequency distribution.
    When we review these ranges, we can see that the last range is misleading as it consists of all data “over 80.” If the bins all had the same width, that last bin would run from 80 to 120. However, we can see from the histogram that the maximum value for this data is between 160 and 200. If the last bin in this bar graph were labeled honestly, it would read “80–200,” which would drive home the fact that the width of that bar is misleading.

Symbols used here

\pm
plus or minus
Both signs at once: x = 3 ± 2 means 5 and 1.
\approx
approximately equal
Equal to the precision shown, not exactly.
n!
factorial
n × (n−1) × … × 1; the number of orderings of n things. 0! = 1.
\binom{n}{k}
binomial coefficient, "n choose k"
Number of k-element subsets of n things: n!/(k!(n−k)!).
\sum_{k=1}^{n} a_k
summation
Add a_k for k = 1 up to n.
A \cup B,\ A \cap B,\ A \setminus B
union, intersection, difference
In either; in both; in A but not B.
\bar{x},\ \mu
sample mean, population mean
Average of the data; average of the whole population.
\sigma,\ s,\ \sigma^2
standard deviation, sample s.d., variance
Typical distance from the mean; its square.
P(A),\ P(A \mid B)
probability, conditional probability
Chance of A; chance of A given that B happened.
E[X],\ \operatorname{Var}(X)
expected value, variance
Probability-weighted average of X; its spread.
N(\mu, \sigma^2),\ z
normal distribution, z-score
The bell curve with mean μ and variance σ²; (x − μ)/σ.

How to: Visualizing Data

  1. Create charts and graphs to appropriately represent data.
  2. Interpret visual representations of data.
  3. Determine misleading components in data displayed visually.
  4. What proportion of available cars were sports cars?
  5. What proportion of available cars were sedans?
  6. Which categories of cars each made up less than 5% of the models available?
  7. The bar for sports cars goes up to 10%, so the proportion of models that are considered sports cars is 10%.
  8. The bar corresponding to sedan goes up past 30% but not quite to 35%. It looks like the proportion we want is between 33% and 34%.

Questions people ask

Mean or median — which should I use?

Median when the data have outliers or a long tail (incomes, house prices); mean when the data are roughly symmetric and you want every value to count. Report both if they disagree — the gap is itself information.

What does a p-value actually say?

The probability of seeing data at least this extreme if the null hypothesis were true. It is not the probability that the null hypothesis is true.

Why divide by n − 1 for the sample variance?

The sample mean sits closer to the sample than the true mean does, so squared deviations from it are slightly too small on average; dividing by n − 1 instead of n corrects the bias.

Versuch es selbst.

Parts of this page are adapted from OpenStax Contemporary Mathematics (CC BY-NC-SA 4.0). Condensed and re-explained here; errors are ours.

Mehr in Statistics & Probability