Public
Edited
Apr 4
Insert cell
md`# Graduated Symbol Mapping
Reported Bigfoot Sightings in Iowa Counties, Source: [The Bigfoot Field Researchers Organizatiion]`
Insert cell
Insert cell
graduatedSymbols = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(topojson.feature(basepolygons, basepolygons.objects.states_simple))
.attr("fill", "#ccc")
.attr("d", path_basemap);
svg.append("path")
.datum(topojson.mesh(basepolygons, basepolygons.objects.states_simple, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path_basemap);
svg.append("g")
.selectAll("circle")
.data(points.features
.map(d => (d.value = Math.sqrt(d.properties[attributeName]), d))
.sort((a, b) => b.value - a.value))
.join("circle")
.attr("transform", d => `translate(${path_points.centroid(d)})`)
.attr("r", d => radius(d.value))
.attr("fill", d => colors(d.value))
.attr("fill-opacity", 1)
.attr("stroke", "#000")
.attr("stroke-width", 0.5)
.append("title")
.text(d => `${d.properties[idName]} : ${format(d.properties[attributeName])}`);
return svg.node();
}
Insert cell
symbolLegendDef = {
return {
type: "symbol",
title: attributeName,
fill: "symbolColor",
size: "symbolSize",
direction: 'Horizontal',
columns: undefined,
rowPadding: 5,
columnPadding: 5,
clipHeight: undefined,
titleOrient: 'Top',
symbolStrokeColor: '#000',
symbolStrokeWidth: 0.5
};
}
Insert cell
height = 610
Insert cell
width = 975
Insert cell
path_points = d3.geoPath().projection(projection)
Insert cell
path_basemap = d3.geoPath().projection(projection)
Insert cell
projection = d3.geoAlbers()
Insert cell
format = d3.format(".2s")
Insert cell
//proportional symbols
//radius = d3.scaleSqrt([0, d3.max(attribute)], [0, 30])
Insert cell
radius = d3.scaleThreshold()
.domain(naturalbreaks)
.range(radiusArray)
Insert cell
sizeArrayForLegend = Array.from(radiusArray, d=>Math.PI*Math.pow(d, 2))
Insert cell
radiusArray = [3, 9, 23, 40]
Insert cell
circleLabels = Array.from(naturalbreaks, d=> format(Math.pow(d, 2)))
Insert cell
colors = d3.scaleThreshold()
.domain(naturalbreaks)
.range(YlOrRd)
Insert cell
YlOrRd = ["#ffffb2", "#fecc5c", "#fd8d3c", "#e31a1c"]
Insert cell
naturalbreaks = simple.ckmeans(attribute, 4).map(v => v.pop())
Insert cell
d3.max(attribute)
Insert cell
attribute = Array.from(points.features, d=>Math.sqrt(d.properties[attributeName]))
Insert cell
attributeName = "AGE_65_UP"
Insert cell
idName = "STATE_NAME"
Insert cell
//import the point data (geojson)
points = FileAttachment("states48_points.geojson").json()
Insert cell
//import the polygon base map data
basepolygons = FileAttachment("states_simple.json").json()
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
topojson = require("topojson-client@3")
Insert cell
import {plot} from '@vega/vega-plot'
Insert cell
d3 = require("d3@5")
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