Unit 3:   Bar, Frequency and Pie Charts

imageUnit 3Bar, Frequency and Pie Charts
Unit Overview

Students learn to create and interpret Bar and Pie charts, as well as Frequency Bar Charts.

Product Outcomes:
    Length: 90 minutes
    Glossary:
    • bar chart: a visualization in which a data set is represented by vertical bars, with length proportional to values

    • category: the set of possible values that a value in a categorical data set can have

    • chart: visual reprsentations of how values in a data set are distributed

    • frequency: how often a particular value appears in a data set

    • frequency bar chart: A bar chart in which each the length of each bar corresponds to the frequency of a particular value

    • pie chart: A chart where the size of each pie slice corresponds to a value in the data set

    Materials:
      Preparation:

        Types

        Functions

        Number

        +, -, *, /, num-sqrt, num-sqr

        String

        n/a

        Image

        draw-plot

        Series

        function-plot, scatter-plot

        List

        extract



        Introduction

        Overview

        Learning Objectives

          Evidence Statements

            Product Outcomes

              Materials

                Preparation

                  Introduction (Time 10 minutes)

                  • image

                    Data scientists often use charts to give a graphical representation of the data. Charts are pictures, where some part of the picture relates to values in a data set. You’ve already seen two kind of plots: a function plot and a scatter plot. Bar charts are used to compare rows in a table by their entries in a particular column. In this example, we are comparing each item on the menu by the amount of cholesterol it has. The length of the bar relates to the amount of cholesterol: shorter bars mean less cholesterol, and higher bars mean more cholesterol.

                    • Which item has the most cholesterol?

                    • Which item has the second most cholesterol?

                    • How much cholesterol does a grilled chicken sandwich have?

                    Highlight that you can very quickly see which items have the most cholesterol, compared to reading an entire table to find out. Reading charts is advantageous for seeing how the rows relate to each other. However, it’s harder to read exact values from charts, as we see from the grilled chicken question.

                  • image

                    Another chart used to compare rows in a table by some column is a pie chart. In pie charts, each row of the table gets a slice of the pie, and the size of the pie slice relates to the value of cholesterol: bigger pie slice means more cholesterol, and a thinner slice means less cholesterol.

                    Later in the unit we will present guidelines for when to use pie charts vs. bar charts. For this example, a bar chart is preferable, but we want students to understand that pie and bar charts are different pictures to represent the same kind of data: one column of labels (food item), and one column of values (cholesterol).

                  • Bar and Pie charts are similar in some ways:

                    • Every row is represented, either as a bar or a pie slice.

                    • The value being examined is proportional to the size of the bar or pie slice.

                    What differences do you see between bar and pie charts?

                    Pie charts are useful for showing percentages, or "how big is this row relative to the size of the whole?" Bar charts show the actual magnitude of each row, independently of the total value.

                  Bar Charts & Pie Charts in Pyret

                  Overview

                  Learning Objectives

                    Evidence Statements

                      Product Outcomes

                        Materials

                          Preparation

                            Bar Charts & Pie Charts in Pyret (Time 25 minutes)

                            • In Pyet, you can easily construct pie charts and bar charts with functions.

                              Open the Unit 3 Starter File, Save a Copy and Run the program. You should see the bar and pie charts from the previous section appear sequentially.

                            • Let’s go through this code together:

                               

                              What does this code do?

                              You’ve seen this code before: Extracting columns from a table as lists. These lists are the labels and values (respectively) that will be used to create our charts.

                              If students cannot explain what these first two lines do, STOP and review.

                            •  

                              This code uses new functions you haven’t seen before: bar-chart and pie-chart. As you might expect, the contracts for these function are:  

                              What do the two arguments in their domains represent?

                              • The first is the list of labels. Each of these will be the name of a bar or pie slice on the chart.

                              • The second is the list of values. Each of these corresponds to the size of a bar or slice on the chart.

                              Write the contracts for these functions in your Contracts page, then use draw-plot with these plots to draw them to screen.

                            • These plots are interactive, allowing you to experiment with the data before you generate the final image. While the plot window is open, it’s interactive: what happens when you hover over a slice of the pie?

                              It reveals the value and percentage of the whole.

                              • Create a bar chart displaying the amount of sodium for each menu item in nutrition.

                              • Create a pie chart showing the GDP of every country in countries.

                              After completing these bar charts, turn to Page 11 in your workbook and answer the questions using these charts.

                              • Students should add 2 more function calls to their definitions window; one using bar-chart, the other using pie-chart.

                              • Emphasize that students should choose informative axis & title names, as if they’re showing these charts to someone who has never seen these tables before.

                            Frequency Bar Charts

                            Overview

                            Learning Objectives

                              Evidence Statements

                                Product Outcomes

                                  Materials

                                    Preparation

                                      Frequency Bar Charts (Time 20 minutes)

                                      • Recall the table of our favorite 4th grade class from Unit 2:

                                        First

                                        Last

                                        Eye-Color

                                        "John"

                                        "Doe"

                                        "Green"

                                        "Jane"

                                        "Smith"

                                        "Brown"

                                        "Javon"

                                        "Jackson"

                                        "Brown"

                                        "Angela"

                                        "Enriquez"

                                        "Hazel"

                                        "Jack"

                                        "Thompson"

                                        "Blue"

                                        "Dominique"

                                        "Rodriguez"

                                        "Hazel"

                                        "Sammy"

                                        "Carter"

                                        "Blue"

                                        "Andrea"

                                        "Garcia"

                                        "Brown"

                                        Turn to Page 12 in your workbook, and complete the exercise using this table.

                                      • By filling in the last bar, you have created a bar chart. However, there’s something special about chart. What is different about this bar chart from the ones we have created before?

                                        • Previous bar charts used a column from the table as the labels, and another column as the values.

                                        • In this bar chart, we are using the categories of a column as the labels, and the frequency of each category as the value.

                                      • Here, we are looking at the Eye Color column, which contains categorical data. In this special kind of bar chart, we are computing the frequency of each category, and that frequency relates to the length of each bar. Since there are 3 people with brown eyes, the bar for Brown extends to 3 marks long.

                                      • This special kind of bar chart is called a frequency bar chart. There’s a function in Pyret that lets us build frequency bar charts from a list:   Below is an example that computes the frequency of categories in the home-state column of presidents.

                                         

                                        What does the argument to freq-bar-chart mean?

                                        • Create a frequency bar chart for the party column in presidents. Which political party has created the most presidents?

                                        • Create a frequency bar chart for the continent column in countries. Which continent has the most countries within it?

                                      Analysis of Charts

                                      Overview

                                      Learning Objectives

                                        Evidence Statements

                                          Product Outcomes

                                            Materials

                                              Preparation

                                                Analysis of Charts (Time 15 minutes)

                                                • For the rest of your life, you will probably see bar charts and pie charts in many different colors and formats. To prepare for this, we’ll practice answering questions about several different bar and pie charts from a variety of sources.

                                                  Complete Page 13 and Page 15 in your workbook by answering the questions about each of the charts.

                                                  This workbook assignment could also become a homework assignment, or be made into a quiz/jeopardy style game.

                                                  Image Sources:

                                                Closing

                                                Overview

                                                Learning Objectives

                                                  Evidence Statements

                                                    Product Outcomes

                                                      Materials

                                                        Preparation

                                                          Closing (Time 20 minutes)

                                                          • Take 30 minutes to answer questions 5 and 6 in your Project Report.

                                                            See the Sample Project Report to see an exemplar of student work.