Public
Edited
Jun 4
Insert cell
Insert cell
Insert cell
import {vl} from "@vega/vega-lite-api-v5"
Insert cell
import {printTable} from "@uwdata/data-utilities"
Insert cell
Insert cell
emissions = FileAttachment("OECD Air emissions - Greenhouse gas emissions Inventories (Unfiltered).csv").csv()
Insert cell
co2Emissions = emissions.slice(53187, 53192)
Insert cell
ghgEmissions = emissions.slice(18503, 18508)
Insert cell
hfcEmissions = emissions.slice(23536, 23541)
Insert cell
ch4Emissions = emissions.slice(33867, 33872)
Insert cell
n2oEmissions = emissions.slice(67997, 68002)
Insert cell
combinedEmissions = n2oEmissions.concat(ch4Emissions.concat(hfcEmissions.concat(ghgEmissions.concat(co2Emissions))))
Insert cell
printTable(combinedEmissions)
Insert cell
Insert cell
emissionsBarGraph = vl.markBar()
.data(combinedEmissions)
.encode(
vl.x().fieldO('TIME_PERIOD').title('Year'),
vl.xOffset().fieldN('POLLUTANT'),
vl.y().average('OBS_VALUE').title('Total Emissions (in Tonnes CO2 Equivalent)'),
vl.tooltip([{field: 'OBS_VALUE', type: 'quantitative', title: 'Tonnes CO2E', formatType: 'iformat'}, {field: 'POLLUTANT', type: 'nominal', title: 'Pollutant'}]),
vl.color().fieldN('POLLUTANT'),
).render();
Insert cell
emissionsLinesPointGraph =
vl.data(combinedEmissions).encode(
vl.x().fieldT('TIME_PERIOD').axis({tickCount: 5}).title('Year'),
vl.detail().fieldN('POLLUTANT'),
vl.y().average('OBS_VALUE').title('Total Emissions (in Tonnes CO2 Equivalent)'),
vl.tooltip([{field: 'OBS_VALUE', type: "quantitative", title: 'Tonnes CO2E', formatType: 'iformat'}, {field: 'POLLUTANT', type: 'nominal', title: 'Pollutant'}]),
vl.color().fieldN('POLLUTANT'),
).layer(vl.mark({type:"point", filled: true}), vl.mark({type:"line"})).render();
Insert cell
Insert cell
vl.vega.expressionFunction('iformat',(datum, params) => {
return ilformat(datum);
});
Insert cell
ilformat = ilocale.format(",");
Insert cell
ilocale = d3.formatLocale({
decimal: ".",
thousands: ",",
grouping: [3]
});
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more