Published
Edited
Nov 16, 2020
20 forks
Importers
198 stars
Election 2020 County Vote Distribution within a State2020 Presidential Election Time Series AnomaliesMontana 2020 Legislative OutcomesDot-density election maps with WebglPennsylvania 2020 General Election Mail Ballot Requests AnalysisElection Night Results2020 Presidential Election Time SeriesUS Electoral College Results 1900 - 2020Facebook Advertising in the 2020 Presidential ElectionUS Presidential Election Results (1976 - 2020)2020 Presidential Election in ChicagoBlue waveElection 2020: How reliable are different results at different stages?Election 2020 Vote–Time Correlation CartogramElection 2020 Vote Count Speed CartogramWhat’s the connection between these two election bar charts?Spinning counties, November 2020A Better Way to Visualize US Elections 2020 ResultsUS Elections 2020 Results - Deeper LookUS Election 2020Indian Country Today #NativeVote2020Indian Country Today #NativeVote2020As votes are countedTry to impeach this? Challenge accepted!Early Voting Wait Times in Gwinnett County, GeorgiaVOTE LogoDonor Age Distribution of 2020 Contributions by Individuals: Trump vs. Sanders2020: Where Donation $$ EmergeUnique Individual Donors contributing to the 2020 Presidential CandidatesContributions: Trump vs. Biden 2020Changes to polling placesElectoral College Unit ShuffleAs votes come in, what would it take for the trailing candidate to win?
Electoral College Decision Tree
2004 - 2016 Presidential Margin of Victory per County2020 State Probabilities by Election Model - Shaded Table2020 Presidential Election ForecastsElection Maps: 2016Working With Election Data: EAVS3a. Historical participation in early voting vs. Election Day votingNC Election MapSouth Carolina Early and Absentee Voting DataRace Bar Chart utilitiesNC Congressional DistrictsGrid cartogramsPaths to the White House (Inferred)US Elections 2018How well does population density predict U.S. voting outcomes?
US Election Convention MapElection Data Tutorial2020 Presidential Election Forecasts2016 U.S. presidential election (PEPSI Remix)2016 U.S. presidential election
USPS collection box changesU.S. Geographic DataU.S. County Visualization IdeasRejected Mail Ballots in North Carolina
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
data = await FileAttachment("electoral_college.csv").csv({ typed: true })
Insert cell
contested = data
.filter(d => d.category === "none")
.sort((a, b) => d3.descending(a.votes, b.votes))
Insert cell
totalD = d3.sum(data.filter(d => d.category === "D").map(d => d.votes))
Insert cell
totalR = d3.sum(data.filter(d => d.category === "R").map(d => d.votes))
Insert cell
decided = new Map(
Object.entries(selectStates).filter(([key, value]) => value !== "none")
)
Insert cell
treeData = {
const root = {
name: "",
votes: 0,
votesD: totalD,
votesR: totalR,
pruned: false
};
function buildTree(node, depth) {
if (depth < contested.length && !winner(node)) {
const state = contested[depth];
node.children = [
{
name: state.name,
shortname: state.shortname,
party: "D",
votes: state.votes,
votesD: node.votesD + state.votes,
votesR: node.votesR,
pruned:
node.pruned ||
(decided.has(state.name) && decided.get(state.name) === "R")
},
{
name: state.name,
shortname: state.shortname,
party: "R",
votes: state.votes,
votesD: node.votesD,
votesR: node.votesR + state.votes,
pruned:
node.pruned ||
(decided.has(state.name) && decided.get(state.name) === "D")
}
];
node.children.forEach(child => buildTree(child, depth + 1));
}
return node;
}
return buildTree(root, 0);
}
Insert cell
function autoBox() {
document.body.appendChild(this);
const { x, y, width, height } = this.getBBox();
document.body.removeChild(this);
return [x - 5, y, width + 10, height];
}
Insert cell
tree = d3
.cluster()
.size([2 * Math.PI, radius])
.separation((a, b) => (a.parent == b.parent ? 1 : 2) / a.depth)
Insert cell
radius = 390
Insert cell
targetWidth = Math.min(width, radius * 2)
Insert cell
circleSize = d3
.scaleSqrt()
.domain(d3.extent(contested.map(d => d.votes)))
.range([2.5, 6.5])
Insert cell
votesScale = d3
.scaleLinear()
.domain([0, 538])
.range([0, targetWidth])
Insert cell
result = d =>
d.votesD > 269
? "D"
: d.votesR > 269
? "R"
: d.votesD === 269 && d.votesR === 269
? "tie"
: null
Insert cell
winner = d => {
const outcome = result(d);
return !outcome || outcome === "tie" ? null : outcome;
}
Insert cell
partyColor = d => (d.party === "D" ? colorD : d.party === "R" ? colorR : "#888")
Insert cell
colorD = "#2a72c9"
Insert cell
colorR = "#c92a2a"
Insert cell
prunedOpacity = 0.05
Insert cell
normalOpacity = 0.3
Insert cell
fullOpacity = 1.0
Insert cell
strokeOpacity = (pruned, highlight) =>
pruned ? prunedOpacity : highlight ? fullOpacity : normalOpacity
Insert cell
stateLabel = d => (width > 800 ? d.name : d.shortname)
Insert cell
candidateD = "Biden"
Insert cell
candidateR = "Trump"
Insert cell
import { form } from "@mbostock/form-input"
Insert cell
d3 = require("d3@6")
Insert cell
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