vl.layer(
vl.markGeoshape({ filled: true })
.data({
url: 'https://raw.githubusercontent.com/vega/vega-datasets/main/data/world-110m.json',
format: { type: 'topojson', feature: 'countries' }
})
.encode(
vl.color().value('lightgray'),
vl.stroke().value('#333'),
vl.strokeWidth().value(0.5)
),
vl.markGeoshape({ filled: true })
.data({
url: 'https://raw.githubusercontent.com/vega/vega-datasets/main/data/world-110m.json',
format: { type: 'topojson', feature: 'countries' }
})
.transform(
vl.lookup('id')
.from(vl.data(highlighted_countries_by_year).key('id').fields(['name', 'co2']))
.as(['name', 'co2']),
{ calculate: "datum.co2 > 0 ? datum.co2 : null", as: "validCO2" }
)
.encode(
vl.color()
.fieldQ('validCO2')
.title('CO₂ Emissions (kt)')
.scale({
type: 'log',
domain: [1, max_co2_emissions],
range: ['#00FF00', '#FFFF00', '#FF0000']
}),
vl.tooltip([
{ field: 'name', title: 'Country' },
{ field: 'co2', title: 'CO₂ Emissions (kt)', format: ',' }
]),
vl.stroke().value('#333'),
vl.strokeWidth().value(0.5)
)
)
.width(900)
.height(600)
.config({ projection: { type: "equalEarth" } })
.title(`CO₂ Emissions by Country (${selectedYear})`)
.render()