bubble2020 = {
const data = merged.filter(
d => d.year === "2020" && d.xpop && d.t_total
);
const chart = vl.layer(
vl.markCircle({opacity: 0.45})
.data(data)
.title("National GHG Footprints (2020): Population vs. Per Capita Emissions (Bubble Area = Total Tonnes/Country)")
.encode(
vl.x({field: "xpop", type: "quantitative",
scale: {type: "log"}, axis: {title: "Population (log)"}}),
vl.y({field: "kg_pc", type: "quantitative",
scale: {type: "log"}, axis: {title: "Per‑Capita GHG kg CO₂‑eq (log)"}}),
vl.size({field: "t_total", type: "quantitative",
scale: {range: [50, 1200]},
legend: {title: "Total GHG, t CO₂‑eq"}}),
vl.tooltip([
{field: "name", type: "nominal", title: "Name"},
{field: "xpop", type: "quantitative", format: ","},
{field: "kg_pc", type: "quantitative", format: ".1f"},
{field: "t_total", type: "quantitative", format: ",.0f"}
]),
vl.color({
field: "t_total",
type: "quantitative",
scale: {type: "log", scheme: "viridis"},
legend: {title: "Total t CO₂‑eq"}
})
),
vl.markText({dy: -6, fontSize: 9})
.data(data)
.encode(
vl.x({field: "xpop", type: "quantitative", scale: {type: "log"}}),
vl.y({field: "kg_pc", type: "quantitative", scale: {type: "log"}}),
vl.text({field: "code", type: "nominal"})
)
)
.width(720)
.height(420)
.render();
return chart;
}