{
const width = 600;
const scatter_sq = width * 0.47;
const hist_width = width * 0.33;
const hist_height = 200;
const brush = vl.selectInterval().encodings('x').resolve('intersect');
const hist = vl.markBar()
.encode(
vl.x().fieldQ('mean_Vict_Age')
.bin({maxbins: 100, minstep: 0.5})
.axis({format: 'd', titleAnchor: 'start'}),
vl.y().count().title(null)
);
const hist_layer = vl.layer(
hist.params(brush).encode(vl.color().value('lightgrey')),
hist.transform(vl.filter(brush))
)
.height(hist_height)
.width(hist_width);
const scatter = vl.markCircle({tooltip: true})
.height(scatter_sq).width(scatter_sq)
.encode(
vl.x().fieldQ('M_VALUE').scale({zero: false}).title("Male Victims"),
vl.y().fieldQ('F_VALUE').scale({zero: false}).title("Female Victims"),
vl.color().if(brush, vl.value('green')).value('grey').scale({scheme: 'tableau10'}),
vl.opacity().if(brush, vl.value(0.8)).value(0.1),
vl.tooltip([vl.fieldN('AREA_NAME')])
)
.title({
text: "Take a look at the Victim statistics in an Area in LA City.",
subtitle: "(by Gender & Age)",
anchor: "start"
});
return vl.hconcat(scatter, hist_layer)
.data(Gender_Crimes)
.render();
}