{
const selectedInterval = vl.selectInterval("selected_interval")
.encodings("y");
const pointPlot = vl.markPoint()
.params(selectedInterval)
.encode(
vl.color().fieldN("drv"),
vl.opacity().if(selectedInterval, vl.value(1)).value(0.3),
vl.size().if(selectedInterval, vl.value(100)).value(10)
);
const linePlot = vl.markLine()
.encode(
vl.stroke().fieldN("drv")
)
.transform(
vl.filter(selectedInterval),
vl.regression("hwy").on("displ").groupby("drv")
);
const mainPlot = vl.layer(pointPlot, linePlot)
.data(mpg)
.encode(
vl.x().fieldQ("displ"),
vl.y().fieldQ("hwy")
);
const histogramPlot = vl.markBar()
.data(mpg)
.transform(
vl.filter(selectedInterval),
)
.encode(
vl.y().fieldQ("hwy").bin(true).scale({domain: [0, 45]}),
vl.x().aggregate("count").scale({domain: [0, 100]})
)
.width(100);
return vl.hconcat(histogramPlot, mainPlot)
.render()
}