Unlisted
Edited
Nov 22
Insert cell
Insert cell
Insert cell
Plot.plot({
title: `Population size`,
projection: {
type: "mercator",
// rotate the projection to reattach the tip of eastern Siberia
rotate: [-10, 0],
// create a valid GeoJSON domain
domain: {
type: "FeatureCollection",
// filter the features on valid properties (there is no "continent" property on this dataset)
features: land.features.filter((d) =>
populationByCountry.get(d.properties.a3)
)
}
},
width,
// set the aspect ratio
height: width * 0.65,
marks: [
Plot.geo(
land.features,
// the centroid transform adds derived X and Y channels, allowing the tip: true option to work normally
Plot.centroid({
// don't filter or the shape is not drawn at all (e.g. North Korea)
fill: (d) => populationByCountry.get(d.properties.a3),
stroke: "black",
strokeWidth: 0.25,
// more advice to improve tip for some countries (US) https://github.com/observablehq/plot/pull/2098
tip: true,
// the title is a single text to show as a tip; you could use normal channels instead
title: (d) => {
const count = populationByCountry.get(d.properties.a3);
return `${d.properties.name}\nPopulation: ${
count ? count.toLocaleString() : "No data"
}`;
}
})
)
],
color: {
type: "quantize",
domain: Array.from(populationByCountry.values()),
range: d3.schemeGreens[5],
unknown: "#ccc"
}
})
Insert cell
import {world110m, world50m} from "@visionscarto/geo"
Insert cell
Insert cell
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