Published
Edited
Nov 13, 2020
Importers
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
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
pivotByRaceColumnNames = pivotbyRaceTable.columnNames().slice(1)
Insert cell
pivotbyRaceTable = tableRelevant
.groupby("locationdesc")
.pivot('stratification1', 'datavalue')
.orderby('locationdesc')
Insert cell
tableRelevant = aq.fromCSV(d3.csvFormat(dataRelevant))
Insert cell
table = aq.fromCSV(d3.csvFormat(data))
Insert cell
groupedDataValueType = d3.group(data, d => d.datavaluetype)
Insert cell
greatestState = d3.least(rolledUpByState, ([, max]) => -max)
Insert cell
rolledUpByState = d3.rollup(
dataRelevant,
v => d3.max(v, d => d.datavalue),
d => d.locationabbr
)
Insert cell
summaryStatsOther = getSummaryStats(
dataRelevant.filter(d => d.stratification1 === "Other, non-Hispanic"),
"datavalue"
)
Insert cell
summaryStatsMultiracial = getSummaryStats(
dataRelevant.filter(d => d.stratification1 === "Multiracial, non-Hispanic"),
"datavalue"
)
Insert cell
summaryStatsHispanic = getSummaryStats(
dataRelevant.filter(d => d.stratification1 === "Hispanic"),
"datavalue"
)
Insert cell
summaryStatsWhite = getSummaryStats(
dataRelevant.filter(d => d.stratification1 === "White, non-Hispanic"),
"datavalue"
)
Insert cell
summaryStatsBlack = getSummaryStats(
dataRelevant.filter(d => d.stratification1 === "Black, non-Hispanic"),
"datavalue"
)
Insert cell
dataRelevantGroupedByState = d3.group(dataRelevant, d => d.locationabbr)
Insert cell
raceEthnicityCategories = new Set(dataRelevant.map(d => d.stratification1))
Insert cell
Insert cell
dataRelevant = data.filter(
d =>
d.question ===
"Prevalence of diagnosed diabetes among adults aged >= 18 years" &&
d.stratificationcategory1 === "Race/Ethnicity" &&
d.datavaluetype === "Crude Prevalence"
)
Insert cell
strat1Values = Array.from(groupedByStrat1.keys()).sort()
Insert cell
groupedByStrat1 = d3.group(data, d => d.stratification1)
Insert cell
stratCatValues = Array.from(groupedByStratCat1.keys()).sort()
Insert cell
groupedByStratCat1 = d3.group(data, d => d.stratificationcategory1)
Insert cell
questions = Array.from(groupedByQuestion.keys()).sort()
Insert cell
groupedByQuestion = d3.group(data, d => d.question)
Insert cell
states = Array.from(groupedByStateAbbr.keys()).sort()
Insert cell
groupedByStateAbbr = d3.group(data, d => d.locationabbr)
Insert cell
columnNames = Object.keys(
data.find(d => Object.keys(d).length === numberColumns)
).sort()
Insert cell
numberColumns = d3.max(data.map(d => Object.keys(d)), d => d.length)
Insert cell
numberRows = data.length
Insert cell
Insert cell
Insert cell
dataName = "U.S. Chronic Disease Indicators: Diabetes"
Insert cell
Insert cell
dataPublisher = "CDC"
Insert cell
Insert cell
dataProvider = "Centers for Disease Control and Prevention, National Center for Chronic Disease Prevention and Health Promotion, Division of Population Health"
Insert cell
Insert cell
dataDescription = md`CDC's Division of Population Health provides cross-cutting set of 124 indicators that were developed by consensus and that allows states and territories and large metropolitan areas to uniformly define, collect, and report chronic disease data that are important to public health practice and available for states, territories and large metropolitan areas. In addition to providing access to state-specific indicator data, the CDI web site serves as a gateway to additional information and data resources.

**Note:** this dataset is a subset of [CDI/BRFSS](https://observablehq.com/@clhenrick/het-data-intake-u-s-chronic-disease-indicators-cdi-brfss).
`
Insert cell
Insert cell
dataUrl = "https://chronicdata.cdc.gov/Chronic-Disease-Indicators/U-S-Chronic-Disease-Indicators-Diabetes/f8ti-h92k"
Insert cell
Insert cell
dataIsPublic = true
Insert cell
Insert cell
historical = true
Insert cell
Insert cell
temporal = Boolean(dataStartDate && dataEndDate)
Insert cell
Insert cell
dataStartDate = 2009
Insert cell
Insert cell
dataEndDate = 2018
Insert cell
Insert cell
geoCovered = "United States"
Insert cell
Insert cell
geoDimensions = ["State"]
Insert cell
Insert cell
geoDimensionsForm = [""]
Insert cell
Insert cell
dataFormats = ["JSON", "CSV"]
Insert cell
Insert cell
noDataCode = ""
Insert cell
Insert cell
hasAPI = dataApiUrl.length > 0
Insert cell
Insert cell
dataApiUrl = "https://chronicdata.cdc.gov/resource/f8ti-h92k.json?yearstart=2018&$limit=10000"
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
format2d = d3.format(".2f")
Insert cell
formatPct = d3.format(".0%")
Insert cell
getSummaryStats = (data, field) => ({
min: d3.min(data, d => d[field]),
max: d3.max(data, d => d[field]),
median: d3.median(data, d => d[field]),
mean: d3.mean(data, d => d[field])
})
Insert cell
Insert cell
coerceNumber = value => (value && !isNaN(value) ? +value : null)
Insert cell
data = {
if (hasAPI && dataApiUrl) {
return fetch(dataApiUrl).then(async res => {
if (res.ok) {
const json = await res.json();
return json.map(parseDatum);
}
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 = () =>
data ? data[Math.floor(Math.random() * data.length)] : undefined
Insert cell
Insert cell
import { button } from "@jashkenas/inputs"
Insert cell
import { toc } from "@mbostock/toc"
Insert cell
import { aq, op } from '@uwdata/arquero'
Insert cell
d3 = require("d3-array@2", "d3-dsv@2", "d3-format@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