Public
Edited
May 9
Insert cell
Insert cell
md`### Sources

Minnesota CAFO Locations <br>
https://mnatlas.org/resources/?id=k_0003

Iowa CAFO Locations <br>
Iowa DNR
https://www.arcgis.com/home/item.html?id=abfbd972640d4e87b6c48dc669775767 --> explanation of animal units
https://geodata.iowa.gov/documents/abfbd972640d4e87b6c48dc669775767/about

Animal Sales https://www.arcgis.com/home/item.html?id=c6710e5f7c694b28b67fcb264dd97df2

Hog Sales https://www.arcgis.com/home/item.html?id=ae95808357df4defa5b90459889478f3

Cattle Production https://www.arcgis.com/home/item.html?id=ff20f7128ead456b8f3939d5f2c40579

Wisconsin CAFO Locations <br>
Socially Responsible Agriculture Project
https://apps.dnr.wi.gov/swampereporting/CAFO/Index

Missouri CAFO Locations <br>
Missouri DNR

EPA NPDES Permits in States and Number of CAFOs in States as of 2023
https://www.epa.gov/npdes/npdes-cafo-regulations-implementation-status-reports`
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append(legend)
.attr("transform", "translate(100,500)");

svg.append("g")
.selectAll("path")
.data(topojson.feature(polygons, polygons.objects.IAcafos_WGS84).features)
.join("path")
.attr("fill", d => color(data.get(d.properties[idAttribute])))
.attr("d", path)
.append("title")
.text(d => `${d.properties[idAttribute]}, ${format(data.get(d.properties[idAttribute]))}`);


return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
//Rotate the map sets the longitude of origin for our UTM projection.
projection = d3.geoAlbers().rotate([95,0]).fitExtent([[10, 10], [width, height]], polygon_features);
Insert cell
polygon_features = topojson.feature(polygons, polygons.objects.IAcafos_WGS84)
Insert cell
data = Object.assign(new Map(d3.csvParse(await FileAttachment("IA_countycafos@2.csv").text(), ({NAME, resp_deaths, crude_resp_rate, Join_Count, ALAND}) => [NAME, {
crudeRate: +crude_resp_rate,
cafoNumber: +Join_Count
}])), {title: ["Crude Death Rate from Respiratory Disease", "CAFO Density"]})
Insert cell
idAttribute = "NAME"
Insert cell
polygons = FileAttachment("IAcafos_WGS84.json").json()
Insert cell
height = 710
Insert cell
width = 975
Insert cell
legend = () => {
const k = 24;
const arrow = DOM.uid();
return svg`<g font-family=sans-serif font-size=10>
<g transform="translate(-${k * n / 2},-${k * n / 2}) rotate(-45 ${k * n / 2},${k * n / 2})">
<marker id="${arrow.id}" markerHeight=10 markerWidth=10 refX=6 refY=3 orient=auto>
<path d="M0,0L9,3L0,6Z" />
</marker>
${d3.cross(d3.range(n), d3.range(n)).map(([i, j]) => svg`<rect width=${k} height=${k} x=${i * k} y=${(n - 1 - j) * k} fill=${colors[j * n + i]}>
<title>${data.title[0]}${labels[j] && ` (${labels[j]})`}
${data.title[1]}${labels[i] && ` (${labels[i]})`}</title>
</rect>`)}
<line marker-end="${arrow}" x1=0 x2=${n * k} y1=${n * k} y2=${n * k} stroke=black stroke-width=1.5 />
<line marker-end="${arrow}" y2=0 y1=${n * k} stroke=black stroke-width=1.5 />
<text font-weight="bold" dy="0.71em" transform="rotate(90) translate(${n / 2 * k},6)" text-anchor="middle">${data.title[0]}</text>
<text font-weight="bold" dy="0.71em" transform="translate(${n / 2 * k},${n * k + 6})" text-anchor="end" dx="+115">${data.title[1]}</text>
</g>
</g>`;
}
Insert cell
color = {
return value => {
if (!value) return "#ccc";
let a = value.crudeRate;
let b = value.cafoNumber;
return colors[y(b) + x(a) * n];
};
}
Insert cell
Insert cell
format = (value) => {
if (!value) return "N/A";
let a = value.crudeRate;
let b = value.cafoDensity;

return `${formatNum(a)} ${data.title[0]}${labels[x(a)] ? ` (${labels[x(a)]})` : ""}
${formatNum(b)} ${data.title[1]}${labels[y(b)] ? ` (${labels[y(b)]})` : ""}`;
}
Insert cell
Insert cell
Insert cell
console.log(d.properties[idAttribute], data.get(d.properties[idAttribute]))
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