{
const scatter_sq = width * 0.47;
const hist_width = width * 0.33;
const num_hist = 4;
const hist_height = (scatter_sq/num_hist)-(6*num_hist)
const brush = vl.selectInterval().encodings('x').resolve('intersect');
const origin_chart = vl.markBar()
.height(50).width(scatter_sq)
.encode(
vl.x().count().title(null),
vl.y().fieldN('Origin'),
vl.color().fieldN('Origin').legend(null).scale({scheme: 'tableau10'}));
const hist = vl.markBar()
.encode(
vl.x().fieldQ(vl.repeat('row'))
.bin({maxbins: 100, minstep: 1})
.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)
.repeat({row: hist_columns});
const scatter = vl.markPoint()
.height(scatter_sq).width(scatter_sq)
.encode(
vl.x().fieldQ("Weight_in_lbs").title("Weight (lbs)"),
vl.y().fieldQ("Miles_per_Gallon").title("MPG"),
vl.color().if(brush, vl.fieldN('Origin')).value('grey').scale({scheme: 'tableau10'}),
vl.opacity().if(brush, vl.value(0.8)).value(0.1),
vl.tooltip(columns)
);
return vl.hconcat(vl.vconcat(origin_chart, scatter), hist_layer)
.data(cars)
.render();
}