Public
Edited
Apr 6
Insert cell
Insert cell
md`Goal`
Insert cell
Insert cell
Insert cell
choropleth = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.attr("transform", "translate(365,20)")
.append(() =>
legend({
color: color,
title: data.title,
width: 260,
tickFormat: ".1%"
})
);
svg.append("g")
.selectAll("path")
.data(counties.features)
.join("path")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 1)
// .attr("fill", function(d){
// console.log(color(data.get(d.properties.FIPS)[1]))
// return color(data.get(d.properties.FIPS)[1]);
// })
.attr("fill", d => color(data.get(d.properties.GISJOIN)))
.attr("d", path)
.append("title")
.text(d => " Hispanic Percentage: " + data.get(d.properties.GISJOIN));

return svg.node();
}
Insert cell
Florida_csv_data = d3.csvParse(await FileAttachment("Florida_Counties_Pop.csv").text(),({GISJOIN, Total_pop, White_alone, Black, Hispanic}) => [GISJOIN, Hispanic/Total_pop])
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
Florida = FileAttachment("florida_counties.json").json()
Insert cell
counties = topojson.feature(Florida, Florida.objects.florida_counties)
Insert cell
Hispanic_Pct = Array.from(Florida_csv_data.values(), d => d[1])
Insert cell
data = Object.assign(new Map(Florida_csv_data), {title: "Hispanic Percentage of Florida Counties"})
Insert cell
data.get("G1200860")
Insert cell
YlOrange = [d3.color("#ffffd4"), d3.color("#fed98e"), d3.color("#fe9929"), d3.color("#cc4c02")]
Insert cell
Quantile = d3.scaleQuantile()
.domain(Hispanic_Pct)
.range(["#ffffd4", "#fed98e", "#fe9929", "#cc4c02"])
Insert cell
color = d3.scaleQuantile()
.domain(Quantile)
.range(YlOrange)
Insert cell
width = 720
Insert cell
height = 560
Insert cell
margin = 150
Insert cell
projection = d3.geoTransverseMercator().rotate([94,0]).fitExtent([[80, 80], [width, height]], counties);
Insert cell
color(40)
Insert cell
path = d3.geoPath().projection(projection);
Insert cell
//Florida_Features = topojson.feature(counties, counties.objects.florida_counties);
Insert cell
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