Public
Edited
Feb 6, 2023
Insert cell
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
states = FileAttachment("states48.json").json()
Insert cell
states_features = topojson.feature(states, states.objects.states48)
Insert cell
csv_data = d3.csvParse(await FileAttachment("states_node_measures_1910_1920.csv").text(),({STATE_FIPS, STATE_NAME, TotalFlow_1910_1920, Inflow_1910_1920, Outflow_1910_1920}) => [+STATE_FIPS, [STATE_NAME, +Inflow_1910_1920/+TotalFlow_1910_1920, +Outflow_1910_1920/+TotalFlow_1910_1920]])
Insert cell
statename = Array.from(csv_data.values(), d => d[1][0])
Insert cell
//this is how to take the values of a variable (column) from all variables you created from the csv file
inflowrate = Array.from(csv_data.values(), d => d[1][1])
Insert cell
outflowrate = Array.from(csv_data.values(), d => d[1][2])
Insert cell
//this is how you map the id column to the values. We will use this for joining with topojson later.
data = Object.assign(new Map(csv_data), {title: ["State", "Inflow Rate", "Outflow Rate"]})
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