Public
Edited
Feb 25, 2024
1 star
Insert cell
md`# Nigeria Household: Amount spent on food`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getStateColor = (d) => {
const state =
d.properties.admin1Name === "Federal Capital Territory"
? "Abuja"
: d.properties.admin1Name;
return colorScale(meanSpendPerHeadByState[state]);
}
Insert cell
getStateSpend = (d) => {
const state =
d.properties.admin1Name === "Federal Capital Territory"
? "Abuja"
: d.properties.admin1Name;
return `${state}

₦${meanSpendPerHeadByState[state].toFixed(0)}`;
}
Insert cell
Insert cell
Insert cell
Insert cell
height = 300
Insert cell
householdData.length
Insert cell
d3.max(householdData, getSpendPerHead)
Insert cell
d3.max(householdData, d=>d.numberInHousehold)
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
meanSpendPerHeadRural = d3.mean(ruralHousehold, getSpendPerHead)
Insert cell
width = 700
Insert cell
d3 = require('d3@5')
Insert cell
import { histogram, ruralHousehold, urbanHousehold, householdData, states, zones, sectors } from '@thehogfather/nigeria-household-survey-wave4'
Insert cell
import { states as statesGeoJSON } from "@thehogfather/nigeria-geo-plot-templates"
Insert cell
import {vl} from '@vega/vega-lite-api'
Insert cell
import {select} from "@jashkenas/inputs"

Insert cell
Insert cell
Insert cell
import {legend} from "@d3/color-legend"

Insert cell
tippy = require('https://unpkg.com/tippy.js@6')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more