Public
Edited
Jan 12, 2024
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
owid-co2-data.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof country = Inputs.select(countries, {label: "Country:"})
Insert cell
Insert cell
Insert cell
Insert cell
kioto_UE
X
year
Y
sum
CO2
Color
Size
Facet X
Facet Y
Mark
line
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
marks: [
Plot.ruleY([0]),
Plot.lineY(
kioto_UE,
Plot.groupX({ y: "sum" }, { x: "year", y: "CO2", tip: true })
),
Plot.lineY(
kioto_UE,
Plot.groupX({ y: "min" }, { x: "year", y: "CO2_1990"})
),
Plot.lineY(
kioto_UE,
Plot.groupX({ y: "sum" }, { x: "year", y: "REDUCTION_CO2_1990"})
)
]
})
Insert cell
Insert cell
countries = d3.group(data, d => d.country)
Insert cell
tallestIndex = d3.maxIndex(data, d => d.co2)
Insert cell
data[tallestIndex]
Insert cell
data1 = FileAttachment("countries@4.csv").csv()
Insert cell
Insert cell
Insert cell
data_UE = {
const countriesInData2 = data2.map(item => item.country);

const filteredData = data.filter(item => countriesInData2.includes(item.country));
console.log(filteredData);

return filteredData;
}
Insert cell
data_UE
SELECT
YEAR,
COUNTRY,
CO2,
CO2_1990::DOUBLE AS CO2_1990,
CO2_1990*0.95 AS REDUCTION_CO2_1990
FROM
(SELECT
year,
country,
co2::DOUBLE AS CO2,
(SELECT co2::double FROM data_UE t2 WHERE t2.country = t1.country AND t2.year = 1990) AS co2_1990
FROM
data_UE t1
where co2 <> '')

--WHERE country = 'Austria'
Insert cell
kioto_UE
Insert cell
CO2_1990 = data_UE.filter(d => d.year === "1990")
.map((d) => {
return {
country: d.country,
co2_1990: d.co2,
reduction_co2_1990: d.co2 * 0.95
}
});

Insert cell
kioto_UE_2 = {
const dataZ = [];
kioto_UE
.forEach((yearData) => {
const year = parseInt(yearData.year);
const quinquennium = year + (5 - year % 5);
dataZ.push({
country: yearData.country,
year: year,
quinquennium: quinquennium,
co2: yearData.CO2,
co2_1990: yearData.CO2_1990,
red_co2_1990: yearData.REDUCTION_CO2_1990
});
});
return dataZ;
}
Insert cell
countries_data = d3.group(kioto_UE_2, d => d.country)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = FileAttachment("owid-co2-data.csv").csv()
Insert cell
import { toc } from "@nebrius/indented-toc"
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