Published
Edited
Apr 6, 2020
Insert cell
Insert cell
Insert cell
graduatedSymbols = {
const svg = d3.create("svg")
.attr("width",width)
.attr("height",height);
svg.append("path")
.datum(topojson.feature(basepolygons, basepolygons.objects.contour))
.attr("fill", "#ccc")
.attr("d", path_basemap);
svg.append("path")
.datum(topojson.mesh(basepolygons, basepolygons.objects.contour, (a, b) => a !== b))
.attr("fill", "#ccc")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("stroke-width",0.3)
.attr("d", path_basemap);
svg.append("g")
.selectAll("circle")
.data(points.features
.map(d => (d.value = 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
/* There are obvious spatial disparity in Chicago community areas in terms of househould income. High income areas are mainly clustered in suburban areas and upper coastline areas. In the central area of Chicago are communities with relatively low household incomes. */
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
height = 800
Insert cell
width = 700
Insert cell
path_points = d3.geoPath().projection(projection)
Insert cell
path_basemap = d3.geoPath().projection(projection)
Insert cell
projection = d3.geoTransverseMercator().rotate([87,0]).fitExtent([[80, 80], [width, height]], neighborhood_features);
Insert cell
neighborhood_features = topojson.feature(basepolygons, basepolygons.objects.contour)
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 = [4, 9, 15, 22]
Insert cell
circleLabels = ["<28.3","78.54","153.94","254.46"]
Insert cell
colors = d3.scaleThreshold()
.domain(naturalbreaks)
.range(Bluecolor)
Insert cell
Bluecolor = ["#f1eef6","#bdc9e1","#74a9cf","#0570b0"]
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
attribute1 = Array.from(points.features, d=>d.properties[attributeName])
Insert cell
attributeName = "MedInc1999"
Insert cell
idName = "community"
Insert cell
//import the point data (geojson)
points = FileAttachment("Chicagopoints.geojson").json()
Insert cell
//import the polygon base map data
basepolygons = FileAttachment("contour.json").json()
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