Quiz 02
Overview
Quiz 02 will be held on December 1st in-class. It will be a 75 minute in-person, timed quiz.
The quiz will cover all material from week 6 (Refine your plots: Tell an effective story) through week 13 (Generative AI for dataviz: The current frontier). It will consist of a series of short answer and free response questions. Questions are designed to evaluate your understanding of concepts and methods. You may be asked to answer conceptual questions, interpret visualizations, apply frameworks for evaluating the effectiveness of visualizations, interpret code and output, and/or create visualizations using sketching, conceptual grammar of graphics, pseudocode, etc.
The quiz is not intended to be cumulative, however it is reasonable to expect that you will need to apply foundational concepts and methods from the first part of the course (weeks 1-5) in order to answer questions about the later material. For example, you may be asked to evaluate a geospatial visualization using Cairo’s five qualities of a great visualization, or to interpret a chart that uses a log scale.
Students with SDS accommodations
Students who have registered SDS accommodations related to timed assignments are implemented by the SDS Alternative Testing Program. You will receive separate instructions from SDS about how to take the quiz with your accommodations. If you have any questions about your accommodations, please contact SDS directly.
Students with religious or other accommodations
If you require an accommodation for quiz 02 on the basis of religious observances, athletics, military service, or another accommodation listed on the course syllabus, please contact us at soltoffbc@cornell.edu by November 25th. Any accommodation requests received after this date are unlikely to be approved.
Rules & Notes
Academic Integrity
- A student shall in no way misrepresent his or her work.
- A student shall in no way fraudulently or unfairly advance his or her academic position.
- A student shall refuse to be a party to another student’s failure to maintain academic integrity.
- A student shall not in any other manner violate the principle of academic integrity.
- This is an individual assignment. Everything in the quiz is for your eyes only.
- The quiz will be held in-person. All responses will be written by hand and submitted on paper.
- You may not use any electronic devices during the quiz.1 This includes laptops, tablets, phones, smartwatches, smart glasses, etc.
- You may not use any physical materials during the quiz. This includes textbooks, notes, calculators, etc. Any required information will be provided in the quiz.
Submission
- All responses will be submitted on paper using the provided forms. Quizzes will be evaluated and returned to you via Gradescope.
Grading
- Each quiz is weighted equally. There will be two quizzes in total, so each quiz is worth 10% of your final grade.
Practice problems
Below are some practice problems you may complete in order to prepare for the quiz. The suggested solution is hidden below each exercise. Try to solve the problem on your own before looking at the solution.
Color contrast and double encoding
-
Rank the three text/background combinations above from most to least legible, and explain the principle behind your ranking.
NoteSuggested solutionA (white on black) > C (yellow on red) > B (gray on black). Legibility depends on the contrast between text and background. White on black has the maximum contrast ratio (21:1). Yellow on red has very different hues but similar lightness, so it is harder to read and vibrates visually; it fails WCAG contrast guidelines for small text. Gray on black has low luminance contrast and is hardest to read.
C and B are both poor, so either order is defensible: the key point is that A is clearly best.
-
A line chart distinguishes rural from urban electricity access using color alone (orange vs. blue lines). Describe two ways to double-encode the difference so that color is not the only cue.
NoteSuggested solutionAny two of:
- Different line types (solid vs. dashed).
- Different point shapes at each observation.
- Direct labels (“Rural”, “Urban”) at the end of each line instead of a legend.
- Whitespace or patterns (e.g., ggpattern) to separate filled areas (more relevant for bars and areas).
- Colors that also differ in lightness, so the lines remain distinct in grayscale.
Evaluating AI-generated alt text
A student asked an AI assistant to write alt text for the chart below.
The assistant returned:
This is a line chart with one thick red line, three gray lines, and one dashed black line. The x-axis shows years from 1990 to 2010 and the y-axis shows percentages from 0% to 100%. South Asia rises to about 90% by 2010. The lines represent different regions of the world.
-
Identify two problems with this alt text.
NoteSuggested solutionAny two of:
- Factual error – South Asia reached about 75% in 2010, not 90%.
- No takeaway – it never says why the chart is included, even though the title states it: access rose everywhere, but sub-Saharan Africa remained far behind.
- Describes styling instead of meaning – “thick red line”, “gray lines”, and “dashed black line” mean nothing to a screen reader user unless they are tied to what they represent (sub-Saharan Africa highlighted, the world average dashed).
- Does not name the regions or the data measured (share of population with electricity access).
-
Rewrite the alt text.
NoteSuggested solutionLine chart of the share of people with access to electricity from 1990 to 2010 in four world regions and the world overall. Access rose everywhere, but sub-Saharan Africa remained far behind: 32% in 2010, compared with 75% in South Asia, 83% worldwide, 88% in Southeast Asia, and 95% in Latin America and the Caribbean.
Map scale and raster basemaps
Both maps below were drawn with get_stadiamap() and ggmap().
-
Which map is small-scale and which is large-scale? Which one shows more detail?
NoteSuggested solutionMap A is small-scale (it covers a large area: the Northeast US and southern Ontario) and Map B is large-scale (it covers a small area: the city of Ithaca). The large-scale map, B, shows more detail (individual streets and neighborhood names).
Map scale is the ratio of map distance to ground distance. A large-scale map has a large ratio (e.g., 1:10,000), so objects appear large. The terms are counterintuitive: “large-scale” means a small area.
-
Map B was created with:
ithaca_bbox <- c(left = -76.53, bottom = 42.425, right = -76.46, top = 42.465) get_stadiamap(bbox = ithaca_bbox, zoom = 14, maptype = "stamen_toner_lite")What does the
bboxargument control, and what does thezoomargument control? What would change if you kept the samebboxbut setzoom = 10?NoteSuggested solution-
bboxsets the geographic extent: the longitude/latitude limits of the area to cover. -
zoomsets the level of detail of the tiles (higher zoom = more, smaller tiles with more features and labels). - With
zoom = 10the map covers the same area, but uses far fewer, coarser tiles: individual streets and neighborhood labels would disappear and the image would look blurry or nearly empty at this extent. (Conversely, a zoom that is too high downloads many tiles and makes labels tiny.)
-
Projecting a national choropleth
Both maps below show the share of occupied homes in each U.S. county that are heated primarily with electricity (American Community Survey, 2020-24).
The only difference in the code is that map B passes both layers (counties and state borders) through shift_geometry():
ggplot() +
geom_sf(
data = shift_geometry(county_heat),
mapping = aes(fill = pct_electric)
) +
geom_sf(data = shift_geometry(us_states), fill = NA)-
Map A is drawn in unprojected longitude/latitude coordinates (NAD83, EPSG:4269). Describe two problems with map A as a visualization of this variable.
NoteSuggested solutionAny two of:
- Alaska’s Aleutian Islands cross the 180° meridian, so the map spans the whole globe in longitude and the contiguous US is squeezed into a small part of the plot.
- Most of the plotting area is empty space (ocean), so the counties people care about are tiny and hard to read.
- Unprojected lat/long is not equal-area: areas at higher latitudes are stretched horizontally, so northern counties (and Alaska) take up more visual area than they should.
- The shape of the US looks flattened and stretched compared with familiar projected maps.
-
shift_geometry()reprojects the data to an equal-area projection (USA Albers Equal Area) and also moves Alaska, Hawaii, and Puerto Rico. Why is an equal-area projection a good choice for a county choropleth?NoteSuggested solutionIn a choropleth, readers judge the overall pattern by how much area is shaded each color. An equal-area projection keeps each county’s drawn area proportional to its true land area, so no region gets extra visual weight just because of its latitude.
-
What does map B distort about Alaska and Hawaii? Why is that trade-off usually acceptable?
NoteSuggested solutionAlaska is shrunk (drawn far smaller than its true size relative to the lower 48), and Alaska and Hawaii (and Puerto Rico) are moved from their true locations into insets below the contiguous US. Distances and relative positions are wrong.
The trade-off is acceptable because the goal is to compare counties, not to show true geographic position. Keeping all states visible at a readable size in a compact layout is more useful than true location, and readers recognize this convention.
Binning a choropleth color scale
The three maps below show the share of occupied homes heated primarily with electricity in each of Tompkins County’s 26 census tracts. They differ only in how the color scale is constructed: one uses a continuous gradient, one uses 5 equal-interval bins, and one uses 5 quantile bins (equal number of tracts per bin).
Source: American Community Survey 2020-24, table B25040.
-
Identify which map (X, Y, Z) uses each method: continuous, equal-interval, and quantile.
NoteSuggested solution- Y = continuous (a smooth color bar in the legend)
- Z = equal-interval (bins of equal width: 0%, 9%, 19%, 28%, 37%, 46%)
- X = quantile (unequal widths: 0%, 15%, 17%, 25%, 36%, 46%, with about 5 tracts in each)
-
For each method, give one strength or weakness as it applies to these maps.
NoteSuggested solutionExamples:
- Continuous: Preserves every difference in the data with no arbitrary cut points, but readers cannot reliably match a shade back to a value or tell apart tracts that differ by a few points; the legend is hard to read precisely.
- Equal-interval: Bins are easy to interpret (each spans the same range), but bin counts can be very uneven. Here the lowest bin contains only a few tracts (including Cornell’s campus, at 0%), so most of the map uses only three or four colors.
- Quantile: Uses every color equally (about 5 tracts per bin), which maximizes visible contrast, but the bin ranges are uneven and some are very narrow (the middle bins span only a few percentage points), so tracts that are nearly identical can land in different colors and the map exaggerates small differences.
Also worth noting: the Cornell campus tract (0%) has only about 111 households, so its estimate is highly uncertain, and it stretches the lowest equal-interval bin.
The grammar of animation
-
Match each component of the grammar of animation to its description.
Component Description 1. Transitions A. How data from other points in time is displayed in the current frame (e.g., trails or faded copies) 2. Views B. How the data is spread across frames and how frames relate to each other over time 3. Shadows C. How new data appears and old data disappears during the animation 4. Entrances/exits D. How aesthetic values are interpolated between states (e.g., linear vs. cubic-in-out) 5. Easing E. How the positional scales (axis ranges) change over the course of the animation NoteSuggested solution1-B, 2-E, 3-A, 4-C, 5-D.
-
The three animations below were made with gganimate from the SE4ALL data. For each one, name the
transition_*()function that produced it, choosing fromtransition_reveal(),transition_states(), andtransition_time(), and explain what in the animation tells you.NoteSuggested solution-
transition_states(): the bars move between three discrete states of a categorical variable (“Urban”, “Total”, “Rural”) and pause on each one, like flipping between facets. The title changes with the current state. -
transition_reveal(): the data gradually extend along the time axis, so each line draws itself from left to right while the earlier years stay visible. -
transition_time(): each frame shows the points at one moment of a continuous time variable, and the points glide between the years in the data (1990, 2000, 2010) with frames spaced evenly in time.
-
-
The title of Animation 3 is written as
labs(title = "Year: {frame_time}"). What does{frame_time}do, and why is it important for this animation? Why does the title often show a year that is not a whole number?NoteSuggested solution{frame_time}is a glue-style placeholder that gganimate replaces, frame by frame, with the time value the frame shows. Without it, viewers could not tell which year a frame shows, so they could not connect the point positions to time.The data only have values for 1990, 2000, and 2010.
transition_time()creates the frames in between by interpolating (tweening) each point’s position, so most frames fall between those years andframe_timeis a fractional value such as 1996.3. Rounding it in the title ({round(frame_time)}) gives cleaner labels.
Evaluating a proposed animation
A classmate proposes the animation below to show how electricity access and renewable energy use changed in every country from 1990 to 2010. It plays all 21 years, with every point moving at once, in 4 seconds, then loops.
-
Watch the animation a few times. Evaluate it using the three considerations for effective animation discussed in class: pace, perplexity, and purpose.
NoteSuggested solution- Pace – 21 years in 4 seconds is about 0.2 s per year, too fast to follow; viewers cannot track any single point or read the year label. Slow it down (e.g., 15-20 seconds, with pauses at the start and end).
- Perplexity – About 165 points in seven colors all moving at once is overwhelming; the eye cannot follow more than a few objects. Many points also overlap near 100% access. About 40 countries have no 2010 values, so their points fade out near the end, which a viewer could mistake for a real change.
- Purpose – It is not clear what the animation is meant to show. If the message is “access rose fastest in South Asia” or “high-renewable countries are often low-access countries that rely on traditional biomass”, the animation must highlight that; otherwise a static chart might do better. Animation is justified only if motion adds something a static view cannot.
-
Describe one alternative design (static or animated) that would communicate change over time more effectively, and explain why.
NoteSuggested solutionAny reasonable alternative with a reason, e.g.:
- A static connected scatterplot or arrow plot from 1990 to 2010 for a handful of highlighted countries, others in gray: shows direction and size of change at a glance and allows comparison.
- Small multiples (facets) by region or by selected years (1990, 2000, 2010): readers compare across panels with no memory load.
- A slower animation with shadows (
shadow_wake()orshadow_mark()) and only a few highlighted countries, so viewers can see trajectories. - A line chart of access over time for each region (like the chart in the alt text problem above), if the point is the trend rather than the relationship.
Debugging a Shiny app
A Shiny app lets users explore UN-Habitat estimates of urban green space: the share of each city’s urban area covered by green areas such as parks, forests, and gardens. The data frame green has one row per city per year, with columns region, country, city, year, green_share, and green_per_capita.
The user picks a region, then a country (an observer updates the country choices whenever the region changes), then a year. The app shows a bar chart of green_share for each city in the selected country and year, and a table summarizing those cities. In the server function, d_country() is a reactive expression that filters green to the selected country.
Each snippet below is a modified version of the app with one mistake. For each one, explain what is wrong and show how to fix it (one or two lines of code is enough).
-
When the app runs, the plot area shows:
Error: object of type 'closure' is not subsettableoutput$plot <- renderPlot({ d_country() |> filter(year == input$year) |> ggplot(mapping = aes(x = green_share, y = city)) + geom_col() + labs(subtitle = str_c(n_distinct(d_country$city), " cities")) })NoteSuggested solutiond_countryis a reactive expression, which behaves like a function. Its value must be accessed by calling it,d_country().d_country$citytries to subset the function itself, which causes the “closure is not subsettable” error. Fix:n_distinct(d_country()$city). -
The app fails to start, with:
Error: Can't access reactive value 'country' outside of reactive consumer. Do you need to wrap inside reactive() or observe()?NoteSuggested solutioninput$countryis read directly in the server function, outside any reactive context, so Shiny cannot track the dependency. Wrap the filtering inreactive()and call it with parentheses: -
The app starts without an error, but where the table should be, the app shows a line of raw code beginning
<table class = 'table shiny-table ...# in the UI plotOutput("plot"), textOutput("summary") # in the server output$summary <- renderTable({ d_country() |> filter(year == input$year) |> summarize( cities = n(), median_share = median(green_share) ) })NoteSuggested solutionEach
render*()function must be paired with the matching*Output()function in the UI.renderTable()produces the HTML markup for a table, buttextOutput()displays whatever it receives as plain text, so the user sees the raw HTML instead of a formatted table.Fix: change the UI to
tableOutput("summary")(or userenderText()if text output was intended).
Truthiness, req(), and validate()
-
Which of the values below does Shiny consider truthy (that is,
isTruthy()returnsTRUE)?"Nairobi" "" NULL 0 NA character(0) FALSE c(NA, 8.9)NoteSuggested solutionTruthy:
"Nairobi",0, andc(NA, 8.9). Falsy:"",NULL,NA,character(0),FALSE.Common mistakes: thinking
0is falsy (it is not; onlyFALSEis), and thinking a vector with anyNAis falsy (only all-NAvalues are). -
In the urban green space app from the previous problem, two problems occur:
- When the app first opens,
input$countryis empty for a moment (before the observer fills in the choices), and the outputs briefly show errors. - Only about 13% of cities have a 2025 estimate, and in 91 of the 164 countries no city has one. When a user selects one of these countries and the year 2025, the plot is blank and the table shows
NA.
For each problem, would you use
req()orvalidate()? Explain what the user would see in each case.NoteSuggested solutionProblem 1:
req(). Addreq(input$country)at the top ofd_country(). The empty value is a temporary state, not something the user did wrong, so the outputs should silently wait: the user sees blank outputs for a moment and then the plot appears, with no error messages.-
Problem 2:
validate(). For example, inside each output after filtering to the selected year:The user sees a clear message in place of the plot and table explaining why nothing is shown, instead of a blank plot or a table of
NAs they might misread as a bug. (A reactive expression for the year-filtered data would avoid repeating the check in both outputs.)
- When the app first opens,
Footnotes
Students with certain SDS accommodations are permitted to use a computer.↩︎












