Published
Edited
Aug 6, 2020
1 star
Insert cell
md`# Example choropleth map of Turkey

İlköğretimde öğretmen başına düşen öğrenci sayısı, 2018. Veri: [TÜİK](http://www.tuik.gov.tr/Start.do)`
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, 975, 410]);

svg.append("g")
.attr("transform", "translate(610,20)")
.append(() => legend({color, title: data.title, width: 260}));
svg.append("g")
.selectAll("path")
.data(topojson.feature(turkey, turkey.objects.collection).features)
.join("path")
.attr("fill", d => color(data.get(d.properties.name)))
.attr("d", path)
.append("title")
.text(d => `${d.properties.name},${(data.get(d.properties.name))}`);
svg.append("path")
.datum(topojson.mesh(turkey, turkey.objects.collection, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path);

return svg.node();
}
Insert cell
data = Object.assign(new Map(d3.csvParse(await FileAttachment("tps@1.csv").text(), ({id, pop}) => [id, +pop])), {title: "Öğretmen başına düşen öğrenci sayısı"})
Insert cell
color = d3.scaleQuantize([10, 24], d3.schemeReds[7])
Insert cell
projection = d3.geoMercator()
.scale(2000)
.center([38,38])
Insert cell
path = d3.geoPath().projection(projection);

Insert cell
format = d => `${d}%`
Insert cell
state = new Map(turkey.objects.collection.geometries.map(d => [d.properties,d.properties.name]))

Insert cell
turkey = FileAttachment("turkey.topojson").json()
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
Insert cell
import {legend} from "@d3/color-legend"
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