Public
Edited
Aug 7, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1152, // use same width as the first chart,
insetLeft: 10,
insetRight: 60,
x: {
round: true,
label: null
},
color:{
scheme: "Reds"
},
marks:[
Plot.barX(monthly_sums, {
x: "month",
interval: "month",
inset: 0, // no gaps
fill: fillVar
})
]
})
Insert cell
fillVar = {
if (barVar === "failures"){
return "failures"
} else {
if (barVar === "total_assets" & Assets === "Assets (adj.)"){
return "total_assets_adjusted"
}
else return "total_assets"
}
}
Insert cell
Insert cell
fails = (await FileAttachment("bfb-data@1.csv").csv({array: true}))
.slice(1, -2)
.map((d) => {
const date = parseDate(d[2]);
const assets = parseAssets(d[3]);
return {
"Bank Name": d[0].split(", ")[0],
"City, State": d[0].split(", ").slice(1).join(", "),
"Date": date,
"Assets": assets,
"Assets (adj.)": adjustForInflation(date, assets),
"Acquirer": d[5]
};
})
Insert cell
parseDate = d3.utcParse("%d-%b-%y")
Insert cell
parseAssets = (x) => parseFloat(x.replace(/[^\d.]/g, ""))
Insert cell
Insert cell
findCpi = {
const bisector = d3.bisector((d) => d.DATE);
return (date) => cpiaucsl[bisector.center(cpiaucsl, date)].CPIAUCSL;
}
Insert cell
adjustForInflation = {
const currentCpi = findCpi(new Date("2023-05-01"));
return (date, value) => currentCpi / findCpi(date) * value;
}
Insert cell
import{aq, op} from "@uwdata/arquero"
Insert cell
monthly_sums = aq.from(fails)
.derive({
month: aq.escape(d => d3.timeFormat("%m")(d.Date)),
year: aq.escape(d => d3.timeFormat("%Y")(d.Date))
})
.derive({month: aq.escape(d => new Date(Date.UTC(d.year, d.month, 1)))})
.groupby('month')
.rollup({
failures: d => op.count(),
total_assets: d => op.sum(d.Assets),
total_assets_adjusted: d => op.sum(d["Assets (adj.)"])
})
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