Public
Edited
Apr 12, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
911-daily-dispatch-count-by-agency.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
rawData = FileAttachment("911-daily-dispatch-count-by-agency.csv").csv({typed: true});

// notes:
// Boston Police Department (BPD)
// Boston Fire Department (BFD)
// Emergency Medical Services (EMS)
Insert cell
Insert cell
// define a set called years for later use
// => it should contain all the years mentioned in the dataset
years = new Set();
Insert cell
// get all the years in dataset
rawData.forEach(obj => years.add(obj.Year));
Insert cell
// have a look at years set
years
Insert cell
callTypes = ['BPD','BFD','EMS'];
Insert cell
data = []
Insert cell
rawData.forEach(d => {
// convert Year+Month to a number used in x axis
const time = d['Year'] + (1/12)*d['Month']

// for each type of call, we need push the object for certain times
callTypes.forEach(callType => {
const number = d[callType];
for (let i=0; i<number; i++){
data.push({year: time, type: callType})
}
})
})
Insert cell
// have a look at the data
data
Insert cell
Insert cell
Plot.plot({
y: {
grid: true
},
marginLeft: 50,
marginBottom: 50,
marginTop: 50,
color: {
legend: true,
},
marks: [
Plot.rectY(data, Plot.binX({y: "count"}, {x: "year", thresholds:d3.range(2010, 2016, 1), fill: "type"})),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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