THINK FIRST·CODE LATER

← Interactive Information Visualization
Chapter 7 · Week 7

The Grammar of Graphics: Tables, Time and Distributions

Answered 0/30 Correct 0
Sign in to save progress across devices
Q1

Who wrote The Grammar of Graphics (1999), the foundation of ggplot2 and Vega-Lite?

Q2

In Altair, which operator layers two charts on the same axes?

Q3

What does alt.Chart(df).transform_aggregate(m="mean(pm25)", groupby=["district"]) produce in the specification?

Q4

What happens by default when you pass a DataFrame with 6,000 rows to alt.Chart(...) and render or call to_dict()?

Q5

Which is usually the best way to chart 2 million trips as "trips per day per district"?

Q6

A table with no keys and two quantitative values (temperature, PM2.5 per reading) is best shown as:

Q7

A table with two keys (weekday, hour) and one value (trip count) is best shown as:

Q8

Why sort a bar chart of mean PM2.5 by value (sort="-y") rather than alphabetically?

Q9

Why is a line connecting the mean PM2.5 of Lucheng, Ouhai and Longwan (x = district) a poor choice?

Q10

In Vega-Lite/Altair, what does the time unit day(start_time) extract?

Q11

Which chart best reveals the weekly commuting pattern (peaks at 8:00 on weekdays, late morning at weekends) in a year of trips?

Q12

Cleveland's "banking to 45°" is advice about:

Q13

Trip durations 4–31 minutes look unimodal with 20-minute bins but show two groups with 5-minute bins. What is the lesson?

Q14

Which Altair encoding draws a histogram with bins of width 5?

Q15

What does a box plot not show well?

Q16

What advantage does an ECDF (empirical cumulative distribution function) have over a histogram?

Q17

line.facet(column="district:N") produces a specification whose top level contains:

Q18

By default, facets in Altair share their y scale. Why is that usually desirable?

Q19

You want a line chart of PM2.5 plus a dashed horizontal line at the guideline value. Which composition?

Q20

Which transform reshapes wide columns (e.g., Jan, Feb, Mar) into key/value rows inside a Vega-Lite chart?

Q21

Which transform computes a 7-day moving average or a rank within groups?

Q22

An AI-generated Altair snippet uses alt.Chart(df).mark_line().encode(x="month", y="trips") where month holds strings like "2026-03". What is the risk?

Q23

Why might you compute an aggregate in pandas and read the chart's transform list?

Q24

What does alt.Chart(df).mark_bar().encode(x="district:N", y="mean(pm25):Q") | alt.Chart(df).mark_line().encode(x="date:T", y="pm25:Q") create?

Q25

Which time unit gives the day of the month (1–31) in Vega-Lite?

Q26

In Munzner's table idioms, a dot plot of mean PM2.5 per district (one dot per district on a common axis) is equivalent in keys/values to:

Q27

You enable alt.data_transformers.enable("vegafusion"). What changes?

Q28 Short answer

For each CityPulse question, name the keys and values, choose an idiom, and write the core Altair encoding: (a) mean PM2.5 per district; (b) trips per weekday and hour; (c) temperature vs. PM2.5 for all readings; (d) daily PM2.5 per district over March.

Q29 Short answer

A colleague's chart computes "mean PM2.5 per district" with Altair transforms (filter 0 ≤ pm25 ≤ 500, aggregate mean per district). The raw data: Lucheng 40, 44, 900; Ouhai 12, 14; Longwan 20, −3, 26. Compute what the chart shows, explain how you would verify it, and say whether you would keep the transforms in the chart or move them to pandas.

Q30 Short answer

You must show the distribution of trip durations (2,000 trips) for members vs. casual riders. Compare three idioms (histogram, box plot, ECDF or violin) for this task, and describe the chart you would deliver, including how you would choose the bin width.