Public
Edited
May 10, 2023
Insert cell
Insert cell
Insert cell
Insert cell
us = FileAttachment("final.json").json()
Insert cell
state = topojson.feature(us, us.objects.final)
Insert cell
Insert cell
us_consumption_2016 = us_consumption.filter(d => d.year === 2016)
Insert cell
total_consumption_2016 = new Map(us_consumption_2016.map(({state, total_alc}) => [state, total_alc]))
Insert cell
states = topojson.feature(us, us.objects.final)
Insert cell
Insert cell
import {addTooltips} from "@mkfreeman/plot-tooltip"
Insert cell
percent = d3.format(".2%") // Function to convert values to percent format with two digits
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vizofyear = Plot.plot({
projection: "albers-usa",
marks: [
Plot.geo(state, {
stroke: "white",
fill: (d) => total_alc_all_year.get(d.properties.NAME),
title: (d) =>
`${d.properties.NAME} County \n ${percent(
total_consumption_2016.get(d.properties.NAME) // Custom tooltip text
)}`
}),
Plot.geo(state, { strokeWidth: 0.05 }),
Plot.geo(states, { stroke: "#fff", strokeWidth: .5 })
],
color: {
scheme: "Spectral",
unknown: "#ddd",
type: "linear",
label: "Total Alcohol Consumption per Capita (Gallons)",
legend: true,
percent: true,
domain: [0, 120, 300, 500, 700, 900]
}
})
Insert cell
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