Public
Edited
Apr 28
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
reducedPardons = {
function countByStatus(a, e) {
if (!a[e.status]) {
a[e.status] = 0;
}
a[e.status] += 1;
return a
}

return pardons.reduce(countByStatus, {});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
bubbleMark = Plot.dot(correctReduced, {
x: "status",
r: "count",
fill: "status"
})
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
pardonPresidents = {
function formatPardon(row) {
// First we will filter our array of presidents to get only the president at the time of the final action
// If for some reason no president shows up, we will default to null or "empty"
let president = presidents.filter(pres => pres.start <= row.final_action_date && pres.end >= row.final_action_date)[0]
|| {president: null, party: null}

// Next, we need to return the row along with the properties of the president that we want.
return {
...row,
presNumber: president.num,
president: president.president,
party: president.party
}
}

// Here we will apply our format function and then filter out any of the values with a null president
return pardons.map(formatPardon).filter(x => x.president)
}
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
Plot.plot({
// Margins and size
marginLeft: 120,
height: 300,
// Scales
x: {
tickSize: 0,
label: null,
},
y: {
tickSize: 0,
},
r: {
range: [0, 50]
},
color: {
range: ["steelblue", "red", "green", "orange"]
},
// Marks
marks: [
Plot.dot(reducedJoined, {
x: "status",
r: "count",
y: "party",
fill: "status"
}),
Plot.text(reducedJoined, {text: "count", y: "party", x: "status", fill: "white", fontSize: 14, fontWeight: "bold", stroke: "black"})
]
})
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