Public
Edited
Oct 28, 2022
1 fork
Importers
8 stars
Insert cell
Insert cell
Insert cell
import {fixedStates} from "@observablehq/excel-data-loading"
Insert cell
Insert cell
laserStrikes = addColumn(fixedStates, 'year', row => row['Incident Date'].getFullYear())
Insert cell
Insert cell
d3.groups(laserStrikes, d => d.year)
Insert cell
Insert cell
strikesByYear = d3.groups(laserStrikes, d => d.year)
.map(d => {
return {
year: d[0],
count: d[1].length
}
})
Insert cell
Insert cell
viewof table = Inputs.table(strikesByYear, {sort: "year"})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.barY(strikesByYear, {x: "year", y: "count", fill: "steelblue"}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
laserStrikesCleaned = laserStrikes.filter(d => d.year > 2016)
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.barY(laserStrikesCleaned, Plot.groupX({y: "count"}, {x: "year", fill: "steelblue"})),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
function addColumn(tableData, newColumnName, newColumnFunction) {
return tableData.map(row => {
let returnObject = row;
returnObject[newColumnName] = newColumnFunction(row)
return returnObject
})
}
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