Public
Edited
Apr 21, 2023
5 forks
Importers
7 stars
Insert cell
# Bertin.js: dorling cartogram
Insert cell
The Dorling cartogram ([Dorling, 1996](https://www.dannydorling.org/wp-content/files/dannydorling_publication_id1448.pdf)), named after the geographer Danny Dorling, is a method of representing absolute quantitative data with proportional circles, while avoiding the superimposition of these. A Dorling cartogram does not preserve the shape, topology or centroids of the objects and is an abstract representation of the spatial configuration of the mapped phenomena. Often, this representation will be used without a background map on top. For this reason, this method can be classified in the family of cartograms.
Insert cell
In **bertin.js**, we can make Dorling cartograms by using the *bubble* type and setting the *dorling* parameter to *true*.
Insert cell
For this **first map**, we represent the population of the countries of the World in 2018 (data from the [Maddison database](https://www.rug.nl/ggdc/historicaldevelopment/maddison/?lang=en)). By hiding the basemap, a representation appears which allows to visualize a global shape of the world deformed according to the population.
Insert cell
data = bertin.merge(countries, "ISO3_CODE", maddison, "countrycode")
Insert cell
viewof hide = Inputs.toggle({ label: "Hide background", value: false })
Insert cell
viewof k = Inputs.range([10, 100], { label: "radius max", step: 1, value: 70 })
Insert cell
bertin.draw({
params: {
projection: d3.geoBertin1953()
},
layers: [
{
type: "bubble",
geojson: data,
values: "pop",
k: k,
dorling: true,
iteration: 100,
fill: "#E95B40",
tooltip: ["$country", "$pop", "(inh.)"],
leg_x: 720,
leg_y: 420,
leg_divisor: 1000,
leg_title: "World Population\nin 2018 (million inh.)",
leg_fill: "#E95B40",
leg_round: 0
},
{
type: "layer",
geojson: countries,
fill: "white",
fillOpacity: hide ? 0.01 : 0.3,
stroke: "none"
},
{ type: "graticule" },
{ type: "outline", fillOpacity: hide ? 0.01 : 1 }
]
})
Insert cell
For this **second map**, we represent cities with a population of more than one million. Here, Dorling's method does not produce an anamorphosis. The method allows us to move the circles away from each other in order to solve the problem of symbol overlap in areas where information is very dense.
Insert cell
dots = bertin.table2geo(cities, "lat", "lng")
Insert cell
bertin.draw({
params: { projection: d3.geoBertin1953() },
layers: [
{ type: "header", text: "Cities with more than one million inhabitants" },
{
type: "bubble",
geojson: dots,
values: "population",
k: 10,
dorling: true,
fill: "#5c7db8",
leg_x: 680,
leg_y: 410,
leg_fontSize2: 7,
leg_title: `Number of inhabitants
in the world's largest cities`,
tooltip: ["$city", "$population", "inh."],
leg_round: -2
},

{
type: "layer",
geojson: countries,
fill: "white",
fillOpacity: 0.3,
stroke: "none"
},
{ type: "graticule" },
{ type: "outline" }
]
})
Insert cell
**Appendix**
Insert cell
maddison = d3
.csv(
"https://raw.githubusercontent.com/neocarto/resources/master/datasets/maddison/output/maddison.csv"
)
.then((d) => d.filter((d) => d.year == "2018"))
Insert cell
countries = d3.json(
"https://gisco-services.ec.europa.eu/distribution/v2/countries/geojson/CNTR_RG_60M_2020_4326.geojson"
)
Insert cell
bertin = require("bertin@latest")
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
d3 = require("d3@7", "d3-geo-projection@4")
Insert cell
cities = d3

.csv(
"https://raw.githubusercontent.com/neocarto/resources/master/datasets/simplemaps_worldcities_basicv1.73/worldcities.csv"
)

.then((r) => r.filter((d) => +d.population > 1000000))
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