vl.data(
pyramid.filter(d => d.Year === 1900 || d.Year === 2000)
)
.facet({
column: {
field: "Year",
type: "ordinal",
header: { title: "Census year", spacing: 30 }
}
})
.spec(
vl
.markBar()
.encode(
vl
.y()
.fieldO("age")
.sort("descending")
.axis({ title: "Age group" }),
vl
.x()
.fieldQ("pop_display")
.axis({ title: "Population", format: "s" }),
vl
.color()
.fieldN("sex")
.legend({ title: "Gender" }),
vl.tooltip([
{ field: "sex", type: "nominal", title: "Gender" },
{ field: "age", type: "ordinal", title: "Age group" },
{ field: "pop_display", type: "quantitative", title: "Population" }
])
)
)
.resolve({ scale: { x: "independent" } })
.width(250)
.height(400)
.render();