Public
Edited
Sep 7, 2023
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
state_adjacencies = {
let postals = contiguous_states.features.map((o) => o.properties.postal);
let adjacency_indices = contiguous_states.features
.map((o, i) => o.properties.neighbors.map((j) => [i, j]))
.flat()
.filter((a) => a[0] < a[1]);
adjacency_indices = adjacency_indices.map((a) => ({
source: postals[a[0]],
target: postals[a[1]]
}));

return adjacency_indices;
}
Insert cell
// This map data comes from Natural Earth:
// https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_1_states_provinces.zip
// I used mapshaper.org to retain only the contiguous US, clip the results to our natural boundary,
// and export the results to TopoJSON.
// I went with Natural Earth in the first place, since it has lat/lon data for an interior point for each region.

contiguous_states = {
let contiguous_states = await (
await FileAttachment("contiguous_states3.json")
).json();
contiguous_states.objects.contiguous_states.geometries =
contiguous_states.objects.contiguous_states.geometries.filter(
(o) => o.properties.postal != "DC"
);
let adjacency_lists = topojson.neighbors(
contiguous_states.objects.contiguous_states.geometries
);
contiguous_states = topojson.feature(
contiguous_states,
contiguous_states.objects.contiguous_states
);
contiguous_states.features.forEach(function (o, i) {
o.properties.neighbors = adjacency_lists[i];
o.properties.color = four_coloring[o.properties.postal];
});
return contiguous_states;
}
Insert cell
// The adjacencies were computed with TopoJSON.neighbors in the construction of contiguous_states.
// After downloading that information, the colors were generated by NetworkX (https://networkx.org/)
// using the following code:

// import networkx as nx
//
// edges = [('WA','ID'),('WA','OR'),('ID','MT'),('ID','OR'),('ID','UT'),('ID','WY'),('ID','NV'),('MT','ND'),('MT','WY'),('MT','SD'),('ND','MN'),('ND','SD'),('MN','SD'),('MN','IA'),('MN','WI'),('MI','OH'),('MI','WI'),('MI','IN'),('OH','PA'),('OH','KY'),('OH','WV'),('OH','IN'),('PA','NY'),('PA','MD'),('PA','DE'),('PA','NJ'),('PA','WV'),('NY','VT'),('NY','NJ'),('NY','CT'),('NY','MA'),('VT','NH'),('VT','MA'),('NH','ME'),('NH','MA'),('AZ','CA'),('AZ','NM'),('AZ','UT'),('AZ','NV'),('CA','OR'),('CA','NV'),('NM','TX'),('NM','CO'),('NM','OK'),('TX','LA'),('TX','OK'),('TX','AR'),('LA','MS'),('LA','AR'),('MS','AL'),('MS','AR'),('MS','TN'),('AL','FL'),('AL','GA'),('AL','TN'),('FL','GA'),('GA','SC'),('GA','NC'),('GA','TN'),('SC','NC'),('NC','VA'),('NC','TN'),('VA','MD'),('VA','KY'),('VA','TN'),('VA','WV'),('MD','DE'),('MD','WV'),('CT','RI'),('CT','MA'),('RI','MA'),('OR','NV'),('UT','WY'),('UT','NV'),('UT','CO'),('WY','CO'),('WY','SD'),('WY','NE'),('CO','NE'),('CO','KS'),('CO','OK'),('SD','NE'),('SD','IA'),('NE','KS'),('NE','IA'),('NE','MO'),('KS','OK'),('KS','MO'),('OK','MO'),('OK','AR'),('IA','MO'),('IA','WI'),('IA','IL'),('MO','IL'),('MO','KY'),('MO','AR'),('MO','TN'),('WI','IL'),('IL','KY'),('IL','IN'),('KY','TN'),('KY','WV'),('KY','IN'),('AR','TN')]
// nodes = []
// for edge in edges:
// nodes.append(edge[0])
// nodes.append(edge[1])
// nodes = list(set(nodes))
// nodes.sort()
//
// G = nx.Graph()
// G.add_nodes_from(nodes)
// G.add_edges_from(edges)
// colors = nx.greedy_color(G)

four_coloring = ({
MO: 0,
TN: 1,
KY: 2,
AR: 2,
CO: 0,
IA: 1,
ID: 0,
NE: 2,
OK: 1,
PA: 0,
SD: 0,
WY: 1,
GA: 0,
IL: 3,
MA: 0,
NV: 1,
NY: 1,
OH: 1,
UT: 2,
VA: 0,
WV: 3,
AL: 2,
AZ: 0,
IN: 0,
KS: 3,
MD: 1,
MN: 2,
MS: 0,
MT: 2,
NC: 2,
NM: 2,
OR: 2,
TX: 0,
WI: 0,
CA: 3,
CT: 2,
LA: 1,
MI: 2,
ND: 1,
NH: 1,
VT: 2,
DE: 2,
FL: 1,
NJ: 2,
RI: 1,
SC: 1,
WA: 1,
ME: 0
})
Insert cell
global = ({ show: "just adjacencies" })
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