Public
Edited
Apr 4, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//reading us json file
//us = FileAttachment("US_county.json").json()
Insert cell
us = FileAttachment("US_county_1920_WGS84@2.json").json()
Insert cell
//extracting us counties object from us json file
//here, we can see the feature collection as objects and their properties and geometries in Array format
us_counties = topojson.feature(us, us.objects.US_county_1920_WGS84)
Insert cell
Insert cell
Populationbyrace_1920.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//applying classification method. [using .length fuction of color valiable to define the number of classes]
//naturalbreaks = simple.ckmeans(white_density, Pinkscheme.length).map(v => v.pop())
Insert cell
Insert cell
Insert cell
//more information on sequential scales: https://observablehq.com/@d3/sequential-scales
// color = d3.scaleSequentialQuantile([...data.values()], d3.interpolateBlues)

// color = d3.scaleQuantile()
// .domain(med_age)
// .range()

//color = d3.scaleThreshold()
// .domain(naturalbreaks)
// .range(YlGnBu)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
choropleth = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.attr("transform", "translate(700,10)")
.append(() =>
legend({
color:quantize_white ,
title: whitedata.title,
tickSize: 5,
width: 300,
height: 60,
tickFormat: ".2f"
})
);

svg.append("g")
.selectAll("path")
.data(us_counties.features)
.join("path")
.attr("transform", "translate(5,1)")
.attr("stroke", "black")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 1)
// .attr("fill", function(d){
// console.log(color(data.get(d.properties.FIPS)[0]))
// return color(data.get(d.properties.FIPS)[0]);
// })
.attr("fill", d => quantize_white(whitedata.get(d.properties.GISJOIN)))
.attr("d", path)
.append("title")
.text(d => " White Rate: " + whitedata.get(d.properties.GISJOIN));

return svg.node();
}
Insert cell
Insert cell
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