Visualize · Week 10

Visualization: Distributions

Compare numeric distributions across groups, then explore categorical counts and proportions. Use histograms, boxplots, and bar charts to make comparisons that match the question and the data.

Oct 26–30Lecture 7 · Classworks 10–13
ImportantStart here this week

Resume Lecture 7 at “🚙 Distributions across groups.” We plan to work through Classworks 10–13 this week. Review or finish the histogram practice in Classwork 10 as needed, then compare groups and explore categorical distributions in Classworks 11–13.

Focus

  • Numeric distributions across drive types
  • Raw rows versus summarized category counts
  • Counts, proportions, and their denominators

Prepare

  • Resume Lecture 7 at Distributions across groups
  • Open an R script and load tidyverse
  • Have Classworks 10–13 ready; use their supplied setup code

Practice

  • Use histograms, facets, and boxplots with mpg
  • Choose geom_bar() or geom_col() for category counts
  • Compare January and July flight records with stacked, side-by-side, and 100% stacked bars

Learning targets

  • Explain how bin width changes the visible detail in a histogram.
  • Compare city fuel economy across drive types using facet_wrap() and geom_boxplot().
  • Distinguish a group’s count in a bin from the proportion of that group in the bin.
  • Use geom_bar() to count raw rows and geom_col() to plot counts already stored in a table.
  • Choose stacked, side-by-side ("dodge"), or 100% stacked ("fill") bars to answer different comparison questions.
  • Identify the numerator and denominator of a displayed proportion, and explain how changing the grouping changes its meaning.

Core pattern: compare numeric distributions across groups

library(tidyverse)

ggplot(data = mpg,
       mapping = aes(x = cty)) +
  geom_histogram(binwidth = 2) +
  facet_wrap(~ drv) +
  labs(x = "City fuel economy (MPG)",
       y = "Number of vehicle configurations")

Each panel shows one drive type: f = front-wheel, r = rear-wheel, and 4 = four-wheel drive. The shared axes and common bin width help us compare typical values, spread, and shape. These are counts, not proportions: because the drive-type groups differ in size, a taller bar alone does not mean a larger share of that group falls in the bin.

In Classworks 10–11, practice histograms and compare numeric distributions with facets and boxplots. In Classwork 12, compare vehicle-category counts using geom_bar() and geom_col(). In Classwork 13, use January and July flight records from nycflights13 to compare counts and shares—and check which records form the denominator each time.

Lecture slides

TipLecture slide shortcuts

Click inside the slide preview, then use:

  • the visible ←/→ controls to page through the slides;
  • your mouse wheel or trackpad to keep scrolling the weekly page;
  • M to open the menu;
  • F to enter fullscreen;
  • E to enter or exit PDF export mode;
  • Ctrl + Shift + F to search within the slides;
  • Esc to exit the menu or fullscreen; and
  • T to switch between dark and light mode.
Lecture 7 · Data Visualization I: Distributions and Group Comparisons · resume at Distributions across groupsView slides in new tab

This week’s materials

Back to top