Published
Edited
Nov 17, 2020
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
table = data ? aq.fromCSV(d3.csvFormat(dataTransformed)) : null
Insert cell
dataTransformed = data.slice(1).map(row =>
row.reduce((acc, d, i) => {
acc[variablesNice[i]] = i < variablesNice.length - 3 ? +d : d;
return acc;
}, {})
)
Insert cell
Insert cell
Insert cell
dataName = "U.S. Census ACS 2018 5 Year Population Estimates"
Insert cell
Insert cell
dataPublisher = "United States Census Bureau"
Insert cell
Insert cell
dataProvider = ""
Insert cell
Insert cell
dataDescription = md`Five-year aggregations of yearly surveys around social, economic, demographic, and housing characteristics of the U.S. population. Used by communities to plan investments and surveys. Covers 87 types of data for 578,000+ geographic areas.

The data compares five year periods that do not overlap. For instance, the 2014-2018 ACS 5-Year estimates can be compared with 2009-2013 ACS 5-Year estimates.

The Census warns that some variables can change over time.

The data is available for the nation, all states (including DC and Puerto Rico), all metropolitan areas, all congressional districts (116th congress), all counties, all places, all tracts and block groups.

- Description source: [The Common Knowledge Project](https://commonknowledge.appspot.com/about)
`
Insert cell
Insert cell
dataUrl = "https://www.census.gov/data/developers/data-sets/acs-5year.html"
Insert cell
Insert cell
dataIsPublic = true
Insert cell
Insert cell
temporal = Boolean(dataStartDate && dataEndDate)
Insert cell
Insert cell
dataStartDate = undefined
Insert cell
Insert cell
dataEndDate = undefined
Insert cell
Insert cell
geoCovered = "United States and its territories"
Insert cell
Insert cell
geoDimensions = [
"nation",
"state",
"county",
"tract",
"metropolitan area",
"congressional district",
"block group"
]
Insert cell
Insert cell
geoDimensionsForm = ["FIPS"]
Insert cell
Insert cell
dataFormats = ["JSON"]
Insert cell
Insert cell
hasAPI = dataApiUrl.length > 0
Insert cell
Insert cell
dataApiUrl = "https://api.census.gov/data/2018/acs/acs5"
Insert cell
Insert cell
dataLicense = "(Public Domain?)"
Insert cell
Insert cell
// e.g. FileAttachment("some-tabular-data-file.csv")
dataFileAttachment = undefined
Insert cell
Insert cell
// e.g. new Date("2020-09-30")
dataFileAttachmentDate = undefined
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Ian Johnson's method that uses the ACS variables JSON mappings
variablesNice = variables
.map(niceLabel)
.map(key =>
key
.replace(/ /gi, "_")
.replace(/:/gi, "")
.replace(/,/gi, "")
)
.concat(["name", "state_fips", "county_fips"])
Insert cell
// see full list of available variables here:
// https://api.census.gov/data/2018/acs/acs5/variables.html
variables = [
"B01001_001E", // total estimated population, (all sexes), sex by age
"B01001_002E", // total estimated population, male, sex by age
"B01001_026E", // total estimated population, female, sex by age
"B02001_002E", // White (includes Hispanic or Latino?)
"B02001_003E", // Black or African American
"B02001_004E", // American Indian or Alaskan Native
"B02001_005E", // Asian
"B02001_006E", // Native Hawaiian or Pacific Islander
"B02001_007E", // Some other race
"B02001_008E", // Two or more races
"B02001_009E", // Two or more races (one is some other)
"B02001_010E" // Three or more races
]
Insert cell
key = "bd155aaa303834a623fa83babc2d2644ac60fbf3"
Insert cell
data = {
if (hasAPI && dataApiUrl) {
return fetch(
`${dataApiUrl}?get=${variables},NAME&for=county:*&in=state:*&key=${key}`
).then(res => {
if (res.ok) return res.json();
return res;
});
}

if (dataFileAttachment) {
return await dataFileAttachment.csv(); // <- change `.csv()` if the data is in another format, e.g. JSON
}
}
Insert cell
sampleDatum = {
anotherSampleDatum;
const d = getSampleDatum();
return d;
}
Insert cell
getSampleDatum = () =>
dataTransformed
? dataTransformed[Math.floor(Math.random() * dataTransformed.length)]
: undefined
Insert cell
Insert cell
import { aq, op } from '@uwdata/arquero'
Insert cell
import { niceLabel } from "@enjalot/us-county-datasets"
Insert cell
import { button } from "@jashkenas/inputs"
Insert cell
import { toc } from "@mbostock/toc"
Insert cell
d3 = require("d3-array@2", "d3-dsv@2")
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