vl.markBar()
.data(data)
.transform(
vl.calculate("toNumber(datum.People) / 1000000").as("PeopleNum"),
vl.calculate("datum.Year === '1900' ? -datum.PeopleNum : datum.PeopleNum").as("MirroredPopulation"))
.encode(
vl.y()
.fieldN("Age")
.sort([
"0", "5", "10", "15", "20", "25", "30", "35", "40", "45",
"50", "55", "60", "65", "70", "75", "80", "85", "90"]),
vl.x()
.fieldQ("MirroredPopulation")
.scale({ domain: [-25, 25] })
.axis({
title: "Population (millions)",
format: ",",
labelExpr: "abs(datum.value)" }),
vl.color().fieldN("Year")
)
.title("How has the distribution of the U.S. population by age changed between 1900 and 2000?")
.width(500)
.height(600)
.render()