Public
Edited
Jan 21, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gppd = aq.fromCSV(
await FileAttachment("global_power_plant_database.csv").text()
)
Insert cell
Insert cell
Insert cell
country_summary = gppd
.groupby("country_long")
.rollup({
total_capacity_mw: (d) => op.sum(d.capacity_mw),
count: op.count()
})
.orderby(aq.desc("total_capacity_mw"))
.reify()
Insert cell
Insert cell
top_15_countries = country_summary.column("country_long").data.slice(0, 15)
Insert cell
fuel_summary = gppd
.groupby("primary_fuel")
.rollup({
total_capacity_mw: (d) => op.sum(d.capacity_mw),
count: op.count()
})
.orderby(aq.desc("total_capacity_mw"))
.reify()
Insert cell
fuel_summary.view()
Insert cell
country_fuel_summary = gppd
.groupby("country_long", "primary_fuel")
.rollup({
total_capacity_mw: (d) => op.sum(d.capacity_mw),
count: op.count()
})
.groupby("country_long")
.derive({
proportion_of_country_capacity: (d) =>
d.total_capacity_mw / op.sum(d.total_capacity_mw)
})
.orderby(aq.desc("total_capacity_mw"))
Insert cell
country_fuel_summary.view(10)
Insert cell
Insert cell
stackedBar("total_capacity_mw")
Insert cell
stackedBar("proportion_of_country_capacity")
Insert cell
stackedBar("count")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Swatches(d3.scaleOrdinal(plant_types, colourScale))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
fuel_group_map.view()
Insert cell
Insert cell
gppd_summarised = gppd.join(fuel_group_map)
Insert cell
Insert cell
fuel_group_to_colour = ({
"Fossil fuels": "#222222",
Nuclear: "#9467bd",
Hydro: "#1f77b4",
Wind: "#2ca02c",
Solar: "#ff7f0e",
Other: "#f4da00"
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
moved_dots = {
const moved_dots = [...dots].filter((d) => d.country_long === "India");

moved_dots.forEach((d) => {
[d.originalX, d.originalY] = [d.x, d.y];
});

d3.forceSimulation(moved_dots)
.force(
"x",
d3.forceX(({ x }) => x)
)
.force(
"y",
d3.forceY(({ y }) => y)
)
.force(
"collide",
d3.forceCollide().radius((d) => Math.sqrt(d.capacity_mw) / 22)
) // collide
.stop()
.tick(50);

return moved_dots;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { Swatches } from "@d3/color-legend"
Insert cell
projection = d3.geoEqualEarth()
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more