Public
Edited
May 11
Insert cell
Insert cell
svg = d3.select(DOM.svg(width, height))
Insert cell
choropleth = svg.append("g")
.selectAll("path")
.data(mapData.counties.features)
.join("path")
.attr("d", path)
.attr("fill", d => colorScale(d.properties.AAR)) // <-- Use numeric property
.attr("stroke", "#ccc");


proportionalSymbols = {
svg.append("g")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(topojson.feature(basepolygons, basepolygons.objects.iacounty_wgs84))
.attr("fill", "#ccc")
.attr("d", path_basemap);
svg.append("path")
.datum(topojson.mesh(basepolygons, basepolygons.objects.iacounty_wgs84, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path_basemap);
const legendRadiusScale = d3.scaleSqrt([0, d3.max([...data.values()])], [0, 5]); // Fixed size for legend

const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(80,550)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data([300, d3.max([...data.values()])])
.join("g");
legend.append("circle")
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("cy", d => -legendRadiusScale(d))
.attr("r", legendRadiusScale);
legend.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(format);
svg.append("g")
.attr("fill", "#7a0177")
.attr("fill-opacity", 0.5)
.attr("stroke", "#f768a1")
.attr("stroke-width", 0.5)
.selectAll("circle")
.data(points.features
.map(d => (d.value = data.get(d.properties.FacilityID), d))
.sort((a, b) => b.value - a.value))
.join("circle")
.attr("transform", d => `translate(${path_points.centroid(d)})`)
.attr("r", d => radius(data.get(d.properties.FacilityID)))
.append("title")
.text(d => `${d.properties.FacilityID} : ${format(d.value)}`);
return svg.node();
}
Insert cell
height = 610
Insert cell
width = 1075
Insert cell
path_points = d3.geoPath().projection(projection)
Insert cell
path_basemap = d3.geoPath().projection(projection)
Insert cell
projection = d3.geoAlbers()
.fitSize([width, height], topojson.feature(countyattributes, countyattributes.objects.iacounties_variables))
Insert cell
format = d3.format(".2s")
Insert cell
radius(50000000)
Insert cell
d3.max([...data.values()])
Insert cell
radius(88371.1)
Insert cell
//proportional symbols
radius = d3.scaleSqrt([0, d3.max([...data.values()])], [0, 20])
Insert cell
data.get("AAR")
Insert cell
Insert cell
//import the polygon base map data
countyattributes = FileAttachment("iacounties_variables.json").json()
Insert cell
counties = topojson.feature(countyattributes, countyattributes.objects.iacounties_variables)
Insert cell
AAR_csvdata = d3.csvParse(await FileAttachment("iacounties.csv").text(),({NAMELSAD, AAR, totalpop,Crude_Rate, Crude_Ra_1}) => [NAMELSAD, +AAR])
Insert cell
choroplethdata = Object.assign(new Map(AAR_csvdata), {title: "Age Adjusted Rate of Colorectal Cancer Incidence"})
Insert cell
Insert cell
data = Object.assign(new Map(csv_data))
Insert cell
csv_data = d3.csvParse(await FileAttachment("afos_attributes.csv").text(),({FacilityID, TotalAnimalUnitsByFacility}) => [FacilityID, +TotalAnimalUnitsByFacility])
Insert cell
//import the point data (geojson)
points = FileAttachment("afos.geojson").json()
Insert cell
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
topojson = require("topojson-client@3")
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