Viewing a saved revision (read-only)
mj_oGxxoxzlEWLVmmC1g-
Created from react-d3-starter template
UN WPP 2024 — Fertility vs. Life Expectancy (Grayscale Edition)
Dataset
- File:
/data/un_wpp_2024.csv(read-only virtual path) - 1,000 country-year rows, 16 countries, years 1960–2024
- Key columns used:
iso_code,location,region,year,total_population,fertility_rate,life_expectancy median_ageis entirely missing in the sample and is ignored.- Loaded at runtime with
d3.csv; the header may span multiple physical lines, so a real CSV parser is required (d3.csv satisfies this).
Visualization
Type: Scatter plot — fertility rate (x) vs. life expectancy (y), one marker per country at its latest available year.
Encodings (strictly monochromatic):
- x:
fertility_rate, linear scale, zero baseline - y:
life_expectancy, linear scale, higher is up - marker shape + gray level:
region— nominal categories use both a distinct shape (circle, square, diamond, triangle, star) and a distinct gray token, so categories remain distinguishable in grayscale/print - marker area:
total_population(sqrt scale, area-honest) - annotations: directional note about the demographic transition; source note with dataset provenance
Interactions:
- Hover/focus highlights a country in near-black and dims the others
- Custom HTML tooltip (white, thin gray border, 8px radius) with tabular numerals and explicit units
- Keyboard focusable marks with visible outlines and ARIA labels
- 180ms restrained transitions; disabled under
prefers-reduced-motion
Design tokens
All grayscale values live in one shared token object in renderScatter.js
mirroring the CSS custom properties in styles.css. Data, scales, and
interaction logic are separated from presentation.
Files
index.html— page shell, import map, Inter fontindex.jsx— mounts<App />App.jsx— loads data, header, tooltip element, source noteviz.js— render entry pointrenderScatter.js— grayscale scatter plotuseContainerDimensions.js— responsive container sizingstyles.css— design tokens and layout stylesREADME.md— this documentation
Visualization Ideas
Transition Trails (Connected Scatter)
- Question: How did each country move through fertility/life-expectancy space from 1960 to 2024?
- Fields:
location,year,fertility_rate,life_expectancy - Encoding: x = fertility, y = life expectancy, one line per country ordered by year, with an endpoint marker at the latest year.
- Interaction: hover a trail to highlight it; label the 1960 and 2024 endpoints.
- Implementation: group rows by
iso_code, sort byyear, and draw withd3.line.
Year Scrubber Scatter
- Question: How did the current scatter look in any given year?
- Fields:
year,fertility_rate,life_expectancy,total_population,region - Encoding: the existing scatter, filtered to the selected year.
- Interaction: a slider plus play button, with fixed axes so motion is comparable.
- Implementation: filter by year and key the join on
iso_code.
Life Expectancy Small Multiples
- Question: Which countries gained the most years of life, and when?
- Fields:
location,year,life_expectancy,region - Encoding: a grid of line charts with shared y-axis, one panel per country, ordered by region.
- Interaction: hover shows the value at that year across all panels.
- Implementation:
d3.groupby country and a sharedscaleLinear.
Fertility Slope Chart, 1960 vs Latest
- Question: Which countries had the largest fertility decline?
- Fields:
location,year,fertility_rate - Encoding: two vertical axes joined by slope lines; line weight shows the size of the drop.
- Interaction: hover highlights a country and shows the delta.
- Implementation: take the min and max year per country.
Dumbbell Plot of Life Expectancy Gain
- Question: How many years were gained per country?
- Fields:
location,year,life_expectancy,region - Encoding: horizontal dumbbells sorted by gain, with shape by region.
- Interaction: sort toggle (gain, start, end).
- Implementation: compute the first and last values per country and use a band scale.
Population Pyramid
- Question: How is the population split by sex for a chosen country and year?
- Fields:
pop_male,pop_female,location,year - Encoding: mirrored horizontal bars with a male-to-female ratio label (totals only, no age bands).
- Interaction: country dropdown and year slider.
- Implementation: negate the male values and share the scale.
Sex Ratio Over Time
- Question: Where do women outnumber men, and how has that shifted?
- Fields:
pop_male,pop_female,year,location - Encoding: lines of
pop_male / pop_femalewith a reference line at 1. - Interaction: toggle countries on and off.
- Implementation: a derived ratio field and
d3.line.
Birth Rate vs Death Rate Natural Increase
- Question: When did birth and death rates diverge and converge?
- Fields:
birth_rate,death_rate,year,location - Encoding: two lines with the area between them shaded, showing natural increase.
- Interaction: country selector.
- Implementation:
d3.areawith y0 = death rate and y1 = birth rate.
Birth–Death Phase Plot
- Question: Which stage of the demographic transition is each country in?
- Fields:
birth_rate,death_rate,year,region - Encoding: x = death rate, y = birth rate, with a diagonal showing zero natural growth, plus trails by year.
- Interaction: hover reveals the year labels.
- Implementation: draw a y = x reference line and use
d3.linefor the trails.
Urbanization vs Fertility Scatter
- Question: Does urbanization go with lower fertility?
- Fields:
urban_pct,fertility_rate,region,total_population - Encoding: x = urban percentage, y = fertility, with region shapes and a gray level.
- Interaction: brush a region to filter linked views.
- Implementation: reuse the shape tokens and add a regression line via a small least-squares function.
Urbanization Heatmap
- Question: How fast did each country urbanize?
- Fields:
location,year,urban_pct - Encoding: a country × year grid with a sequential gray ramp.
- Interaction: tooltip with exact values.
- Implementation:
scaleSequential(interpolateGreys)and rects.
Regional Population Stacked Area
- Question: How did regional shares of the sampled population change?
- Fields:
region,year,total_population - Encoding: stacked areas by region, with the gray-level token as the fill.
- Interaction: toggle between absolute and normalized (100%) views.
- Implementation:
d3.rollupby region and year, thend3.stack.
Population Bump Chart
- Question: How did country population ranks change?
- Fields:
location,year,total_population - Encoding: rank on y, year on x, with lines per country.
- Interaction: hover highlights one country's path.
- Implementation: rank within each year, sampling every 5 years.
Fertility Ridgeline by Region
- Question: How does the fertility distribution shift over decades?
- Fields:
fertility_rate,region,year - Encoding: stacked density curves per decade, faceted by region.
- Interaction: toggle the decade.
- Implementation:
d3.binor a kernel density estimate. With 16 countries, label the samples as sparse.
Median Life Expectancy Box Plots by Region
- Question: How much do countries within a region differ?
- Fields:
region,life_expectancy,year - Encoding: box plots with jittered points, and a year selector.
- Interaction: hover a point to see the country.
- Implementation: use quantiles from
d3.quantile.
Bubble Timeline with Fertility Replacement Line
- Question: When did countries fall below replacement fertility (about 2.1)?
- Fields:
fertility_rate,year,location - Encoding: a dot per country-year on a time axis, with a reference line at 2.1 and the first crossing year highlighted.
- Interaction: hover to see the crossing year.
- Implementation: find the first year with fertility < 2.1 per country.
Rate-of-Change Diverging Bars
- Question: Which countries improved fastest in each decade?
- Fields:
life_expectancy,year,location - Encoding: diverging bars of the decadal change in life expectancy, in two gray tones for positive and negative.
- Interaction: choose the decade.
- Implementation: difference between the values at year and year−10.
Parallel Coordinates of Demographic Indicators
- Question: What profile does each country have across the indicators?
- Fields:
fertility_rate,life_expectancy,urban_pct,birth_rate,death_rate,location - Encoding: one polyline per country at its latest year, with a gray level by region.
- Interaction: drag to brush an axis and filter the lines.
- Implementation: one
scaleLinearper axis and and3.brushYon each.
Correlation Matrix
- Question: Which indicators move together?
- Fields:
fertility_rate,life_expectancy,urban_pct,birth_rate,death_rate,median_age - Encoding: a grid of correlation coefficients in a gray ramp, with the value printed in each cell.
median_ageis missing in this sample, so it is excluded. - Interaction: click a cell to open the matching scatter.
- Implementation: compute pairwise Pearson correlation over valid rows.
Country Profile Card with Sparklines
- Question: What is one country's full demographic story?
- Fields: all numeric fields for the selected
location - Encoding: key numbers for the latest year next to sparklines of fertility, life expectancy, and urbanization.
- Interaction: country search that syncs with a selection from the main scatter.
- Implementation: a side panel using shared state in
App.jsx.