Students learn about functions that create data visualizations.
Lesson Goals |
Students will be able to…
|
Student-facing Lesson Goals |
|
Materials |
|
Supplemental Materials |
|
🔗Bug Hunting 10 minutes
Overview
This activity focuses on what we can learn about Pyret functions from the messages we get back in the Interactions Area. The error messages in this environment are specially-designed to be as student-friendly as possible. By explicitly drawing their attention to errors, you will be setting them up to be more independent in the future.
Launch
Before we explore some new functions in Pyret, let’s see how error messages in Pyret can help us to figure out the contract for a function we’ve never seen before.
-
Let’s complete the first section of Catching Bugs when Sorting Tables together. We’ll be working in Animals Starter File.
-
Start by typing
sort
into the Interactions Area, and hit the "Enter" or "Return" key to run this code.
-
What do you get back?
-
<function:sort>
-
This means that the computer knows about a function called
sort
.
-
We know that all functions will need an open parentheses and at least one input!
-
We don’t know the Domain, so we don’t know how many inputs or what types they are. But we can always guess, and if we get it wrong we’ll use the error message as a clue.
-
Type
sort(animals-table)
in the Interactions Area and read the error message.
-
What hint does the error message give us about how to use this function?
-
-
The the sort function expects 3 arguments and its Domain is Table, String, Boolean. If we don’t give it those three things we’ll get an error instead of the sorted table we want.
Investigate
Mistakes happen, especially if we’re just figuring things out! Diagnosing and fixing errors are skills that we will continue developing throughout this course.
-
Turn to the second section of Catching Bugs when Sorting Tables with your partner and try to explain the difference between syntax and contract errors in your own words.
-
Then turn to the third section of Catching Bugs when Sorting Tables. Read each error message carefully, decide whether it’s a contract error or a syntax error and work together to decipher what it’s trying to tell us.
Synthesize
-
What kinds of syntax errors did you find?
-
What kinds of contract errors did you find?
🔗Functions for Making Data Visualizations 20 minutes
Overview
Students will be introduced to functions for making one-variable visualizations in Pyret, including: pie-chart
, bar-chart
, box-plot
and histogram
.
The goal here is for students to become familiar with using Contracts to write expressions that will produce visualizations. But knowing how to make a histogram doesn’t mean a student really understands histograms, and that’s OK!
Once students know how to use Contracts to write expressions to make these visualizations, we have dedicated, in-depth lessons focused on understanding Bar and Pie Charts, Histograms: Visualizing "Shape", Histograms: Interpreting "Shape", Introduction to Box Plots, Scatter Plots, Linear Regression, Advanced Data Visualizations, etc.
Launch
The count
function summarized the data for a single variable in a new table.
The same information could be communicated as a picture! This is called data visualization, and Pyret has functions that can make visualizations for us!
Investigate
Turn to Exploring Data Visualizations. Let’s look at the first function together.
-
What is the name of the function?
-
bar-chart
-
What is the Domain of the function?
-
Table, String
-
What is the Range of the function?
-
Image
-
Take a minute and see if you and your partner can write an expression that will generate a
bar-chart
. -
Did
bar-chart
consume a categorical or quantitative column of data? -
categorical
-
What does the resulting visualization tell us?
-
Make a sketch of the visualization you just built in Pyret.
-
Then work to complete Exploring Data Visualizations, generating each of the other 3 visualizations. Some of them may be new to you - you are not expected to be an expert in them yet, but you should be able to figure out how to use the Contract to get them building!
If your students are already familiar with scatter plots, linear regression plots, and line graphs, you may also want to have them complete Exploring Data Visualizations (2).
Just as we can use Circles of Evaluation to help us combine sort
, count
, and first-n-rows
, we can put Circles of Evaluation to work to help us write code to build more specific visualizations. Consider this:
-
What expression would this Circle of Evaluation generate?
-
-
What would be the resulting visualization?
-
a pie chart showing the species of the 10 youngest animals
-
Practice what you’ve learned on Composing Functions: Match Descriptions to Circles of Evaluation.
-
Be ready to discuss your answers with the class!
-
Complete Circles of Evaluation: Composing Functions to Make Visualizations.
-
Then consider what visualization it might be interesting to compare each of the visualizations on this page with.
-
Visualizations are often most informative when compared with other visualizations.
-
For example, we may want to see how the age range of the animals adopted quickly compares to the age range of all the animals or of the animals that were adopted slowly.
-
For more practice making tables and visualizations by composing functions, have students complete Circles of Evaluation: Composing Functions to Make Visualizations (2)
Synthesize
-
Which visualizations worked with categorical data?
-
pie-chart
andbar-chart
-
Why might you choose a bar chart over a pie chart or vice versa?
-
pie-chart
only makes sense when you have the full picture, since it’s representing the proportion of the whole -
bar-chart
shows the absolute amount in each bar, but it’s harder to see any one bar as a proportion of the whole. -
How are bar charts and histograms different?
-
bar-chart
summarizes categorical data. Each bar represents the count of a specific category. -
histogram
displays the distribution of quantitative data across the range.
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927).
Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.