render({
mark: { type: 'bar', tooltip: true },
data: { values: census },
encoding: {
x: {
aggregate: 'sum', field: 'people',
title: 'Sum of people (all years)',
axis: { format: ',d' }
}
},
width: 640
})
render({
mark: { type: 'bar', tooltip: true },
data: { values: census },
encoding: {
x: { field: 'year', type: 'O', axis: { labelAngle: 0 } },
y: { aggregate: 'sum', field: 'people' }
},
width: 640,
height: 300
})
render({
mark: { type: 'bar', tooltip: true },
data: { values: census },
encoding: {
x: { field: 'year', type: 'O', axis: { labelAngle: 0 } },
y: { aggregate: 'sum', field: 'people' },
color: { field: 'sex', type: 'N' }
},
width: 640,
height: 300
})
render({
mark: { type: 'bar', tooltip: true },
data: { values: census },
encoding: {
column: { field: 'sex', type: 'N' },
x: { field: 'year', type: 'O', axis: { labelAngle: 0 } },
y: { aggregate: 'sum', field: 'people' },
color: { field: 'sex', type: 'N' }
},
width: 400,
height: 300
})
render({
mark: { type: 'bar', tooltip: true },
data: { values: census },
encoding: {
column: { field: 'year', type: 'N', title: null, spacing: 5 },
x: { field: 'sex', type: 'N', title: null },
y: { aggregate: 'sum', field: 'people' },
color: { field: 'sex', type: 'N' }
},
height: 300
})
render({
mark: { type: 'bar', tooltip: true },
data: { values: census },
transform: [
{ filter: 'datum.year === 2000' }
],
encoding: {
column: { field: 'sex', type: 'N', title: null, spacing: 10 },
x: { aggregate: 'sum', field: 'people' },
y: { field: 'age', type: 'O', scale: { reverse: true } },
color: { field: 'sex', type: 'N' }
},
width: 320,
height: 300
})
const rows = await FileAttachment('../../../data/census.txt').tsv({ typed: true });
const census = rows.map(datum => {
const marst = alias_marst.get(datum.marst);
const sex = alias_sex.get(datum.sex);
const order = -marst_domain.indexOf(marst);
return { ...datum, marst, sex, order };
});
const alias_sex = new Map().set(1, 'Male').set(2, 'Female')
const alias_marst = new Map()
.set(0, 'Unknown')
.set(1, 'Married')
.set(2, 'Married, Spouse Absent')
.set(3, 'Separated')
.set(4, 'Divorced')
.set(5, 'Widowed')
.set(6, 'Single')
const marst_domain = [
'Unknown',
'Single',
'Widowed',
'Divorced',
'Separated',
'Married, Spouse Absent',
'Married'
]
const colors = [
'#C7C7C7',
'#9EDAE5',
'#7F7F7F',
'#9467BD',
'#F7B6D2',
'#FFBB78',
'#FFBB78'
]