Public
Edited
Apr 10, 2024
Insert cell
Insert cell
- First Name: Akriti
- Last Name: Saxena
- Student ID: 801367163
Insert cell
Insert cell
climate = FileAttachment("climate-change.csv").csv({ typed: true })
Insert cell
climate
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
climateFiltered = climate.filter(d => (
d['Country Name'] === 'India' ||
d['Country Name'] === 'Sweden' ||
d['Country Name'] === 'United States' ||
d['Country Name'] === 'Japan' ||
d['Country Name'] === 'Spain'
));
Insert cell
Plot.plot({
marks: [
Plot.lineY(climateFiltered, {
x: { scale: 'linear' }, // Change x-axis scale to linear scale
y: { scale: 'linear' }, // Set y-axis scale to linear
x: "Year",
y: "average_value_CO2 emissions (kt)",
stroke: "Country Name",
strokeWidth: 2, // Increase the stroke width for better visibility
tip: true
}),
Plot.dot(climateFiltered, {
x: "Year",
y: "average_value_CO2 emissions (kt)",
fill: "Country Name",
shape: "circle", // Change mark type to circles
size: 50 // Increase the size of the circles for better visibility
})
],
color: { legend: true }
})

Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
// Use a stacked area chart to show cumulative CO2 emissions over time
Plot.areaY(climateFiltered, {
x: "Year", // Define x-axis as "Year"
y: { scale: 'linear' }, // Set y-axis scale to linear
y: "average_value_CO2 emissions (kt)",
fill: "Country Name", // Fill the area with color based on country
fillOpacity: 0.7, // Set fill opacity to 0.7 for better visibility
tip: true
}),
// Highlight the maximum CO2 emissions for each country with a tooltip
Plot.tip(climateFiltered, Plot.selectMaxY({
x: "Year",
y: "average_value_CO2 emissions (kt)",
stroke: "Country Name",
anchor: "right",
fill: "yellow"
})),
// Add text labels for the last year's CO2 emissions for each country
Plot.text(climateFiltered, Plot.selectLast({
x: "Year", // Define x-axis as "Year"
y: "average_value_CO2 emissions (kt)",
text: "Country Name",
fill: "Country Name"
}))
],
color: { legend: true }
})


Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.line(climateFiltered, {
x: "Year",
y: "average_value_Agricultural land (% of land area)",
stroke: "average_value_CO2 emissions (kt)",
strokeWidth: 6,
opacity: 0.8,
tip: true
})
],
scales: {
x: { type: "linear", nice: true },
y: { type: "linear", nice: true }
},
color: { legend: true }
});
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
// Bar chart for CO2 emissions
Plot.rectY(
climateFiltered,
Plot.binX(
{ y: "mean" },
{
x: "Year",
fill: "average_value_CO2 emissions (kt)",
y:"average_value_Agricultural land (% of land area)",
opacity: 0.45,
tip: true,
scale: 'log',
}
)
),
],
color: { legend: true }
})
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