Public
Edited
Apr 1
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
format = d => `${d}%`
Insert cell
topojson = require("topojson-client@3")
Insert cell
US = FileAttachment("dtl_cnty (1).json").json()
Insert cell
counties = topojson.feature(US, US.objects.dtl_cnty)
Insert cell
csv_data = d3.csvParse(await FileAttachment("National_Risk_Index_Counties_807384124455672111-3 (2)@1.csv").text(),({FIPS, Index}) => [+FIPS, +Index])
Insert cell
csv_data_objects = Object.assign((d3.csvParse(await FileAttachment("National_Risk_Index_Counties_807384124455672111-3 (2)@1.csv").text(), d3.autoType)).map(({FIPS, Index}) => ({FIPS: +FIPS, WildfireRiskIndex: +Index})))
Insert cell
data = Object.assign(new Map(csv_data), {title: "Assessing Wildfire Risk by County"})
Insert cell
risk = Array.from(csv_data.values(), d => d[1])
Insert cell
YlGnBu = [d3.color("#ffffcc"), d3.color("#a1dab4"), d3.color("#41b6c4"), d3.color("#2c7fb8"),d3.color("#253494")]
Insert cell
naturalbreaks = simple.ckmeans(risk, YlGnBu.length).map(v => v.pop())
Insert cell
color = d3.scaleThreshold()
.domain(naturalbreaks)
.range(YlGnBu)
Insert cell
width = 1075
Insert cell
height = 610
Insert cell
margin = 500
Insert cell
projection = d3.geoAlbers().fitExtent([[margin, margin], [width - margin, height - margin]], counties)
Insert cell
path = d3.geoPath().projection(projection);
Insert cell
choropleth = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.attr("transform", "translate(140,20)")
.append(() =>
legend({
color: color,
title: data.title,
width: 750,
tickFormat: "0.1f"
})
);

svg.append("g")
.selectAll("path")
.data(counties.features)
.join("path")
.attr("stroke", "black")
.attr("stroke-linejoin", "bevel")
.attr("stroke-width", 0.2)
// .attr("fill", function(d){
// console.log(color(data.get(d.properties.FIPS)[0]))
// return color(data.get(d.properties.FIPS)[0]);
// })
.attr("fill", d => color(data.get(+d.properties.FIPS)))
.attr("d", path)
.append("title")
.text(d => " Risk Index: " + data.get(+d.properties.FIPS));

return svg.node();
}
Insert cell
data.get(1001)
Insert cell
viewof bins = Inputs.range([0, 20], {step: 1, label: "Bins"})
Insert cell
Plot.plot({
marks: [
Plot.rectY(csv_data_objects, Plot.binX({y: "count"}, {x: "Wildfire Risk Index", thresholds: bins})),
Plot.ruleY([0])
]
})
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