vl.markBar()
.title("Age Distribution of the U.S. Population in 1900 vs 2000 ")
.data(census)
.transform(
vl.groupby('Year')
.joinaggregate(vl.sum("People").as("Total_population")),
vl.calculate('datum.People / datum.Total_population * 100').as('Percentage')
)
.encode(
vl.x().fieldO('Age').title('Age Group (Binned Into 5-Year Segments)').sort(null),
vl.y().sum('Percentage').title("Percentage (%) of Yearly Total Population"),
vl.tooltip().sum('Percentage').format('0.2f'),
vl.color().fieldN('Year').title('Character Type').scale({scheme: 'set1'}),
vl.xOffset().fieldN('Year'),
)
.render()