Published
Edited
Sep 25, 2021
Insert cell
Insert cell
# todo
<div style="background-color:#FFE74C">
Add nitrate levels, to show the regional increase of cattle levels to the increase in NO³ levels/
https://observablehq.com/@hellonearthis/north-south-island-nitrate-levels-from-animals
https://observablehq.com/@hellonearthis/nz-regions-nitrate-levels-from-animals/2

# Sediment levels
https://observablehq.com/@hellonearthis/sediment-samples-in-regions-of-aotearoa
Insert cell
Plot.plot({
width: width,
marks: [
Plot.barX( stock, {
x: d=> d.count,
y:'year',
fill: "animal",
title: d=> d.animal + " " + f(d.count)
}),
Plot.ruleX([0])
]
})
Insert cell
Insert cell

Plot.plot({
width: width,
height: 500,

y: {
// tickFormat: d => d.count,
label: `Number of stock`,
// transform: d => d / 1000
},
marks: [
Plot.ruleX([0]),
Plot.barY(region_data, {
x: "year",
y: "count",
fill: "animal",
title: d=> `${d.region} ${d.animal} ${f(d.count)}`,
}),
]
})
Insert cell
region_data = {
let rdata = []
stock_region.map( d=> {
if (d.region == reg) rdata.push(d)
})
return rdata
}
Insert cell
st = FileAttachment("livestock-numbers-clean-1971-2019.csv").csv({typed: true})
Insert cell
stock = {
let s = []
st.map(d => {
if ((d.geography_type == 'New Zealand') && (d.animal != "Total cattle")) s.push({year:d.year,animal:d.animal,count:d.count})
})
return s
}
Insert cell
Insert cell
stock_region = {
let s = []
st.map(d => {
if ((d.geography_type == 'Region' ) && (d.animal != "Total cattle"))
s.push({region:d.geography_name,year:d.year+'',animal:d.animal,count:d.count})
})
return s
}
Insert cell
Insert cell
region_names = {
let s = stock_region.map(d=> {
return d.region
})
return _.uniq(s)
}
Insert cell
Insert cell
regions_minmax = {
let regionMinMax = []
for (let r = 0; r < region_names.length; ++r) {
let mm = d3.extent(stock_region, d=> {
if (d.region == region_names[r]) return d.count
})
regionMinMax.push({[region_names[r]]:mm})
}
return regionMinMax
}
Insert cell
Insert cell
Insert cell
no3 = FileAttachment("no3_stack_ready.json").json()
Insert cell
f = d3.format(",")
Insert cell
import {swatches as Swatches} from "@d3/color-legend"
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