Public
Edited
Jun 15, 2021
Insert cell
Insert cell
maine = {
const width = 800, height = 800;
const svg = d3.select(DOM.svg(width, height))
const projection = d3.geoMercator()
.fitExtent([[0,0],[width, height]], geoME)
const extent = d3.extent(geoME.features, (d) => d.properties.vaxrate);
const color = d3.scaleSequential(extent, d3.interpolateBlues);
svg.append("g")
.attr("transform", "translate(610,20)")
.append(() => legend({color, width: 260, tickFormat: ".0%"}));
let path = d3.geoPath()
.projection(projection);
svg.append('g').selectAll('path')
.data(geoME.features)
.join('path')
.attr('d', path)
.attr("fill", d => color(d.properties.vaxrate))
.style('stroke', 'rgba(0,0,0,.3)')
.on('mouseover', function (e, d, i) {
tooltip
.html(
`<div>${d.properties.name}:
${d.properties.vaxrate ? format(d.properties.vaxrate*100)+"%" : "unknown"}</div>`)
.style('visibility', 'visible');
// TODO: highlight zip somehow
//d3.select(this).attr('fill', 'blue');
})
.on('mousemove', function (e) {
tooltip
.style('top', e.pageY + 10 + 'px')
.style('left', e.pageX + 10 + 'px');
})
.on('mouseout', function () {
tooltip.html(``).style('visibility', 'hidden');
//d3.select(this).transition().attr('fill', 'green');
});
return svg.node()
}
Insert cell
data = FileAttachment("maine_vax_by_zip_06_15_2021.csv").tsv({typed: true})
Insert cell
// I just grabbed this geojson from github, it may not be perfect
geoME = await d3.json("https://raw.githubusercontent.com/OpenDataDE/State-zip-code-GeoJSON/master/me_maine_zip_codes_geo.min.json");

Insert cell
format = d3.format(".2f")
Insert cell
geoME.features.forEach(f => {
const d = data.filter(dd => dd['Zip Code'] == f.properties.ZCTA5CE10);
if (d.length > 0) {
f.properties.vaxrate = d[0]["Vaccination Rate 6-14"];
f.properties.name = `${f.properties.ZCTA5CE10} (${d[0].Town})`;
} else {
f.properties.name = f.properties.ZCTA5CE10;
f.properties.vaxrate = undefined;
}
})
Insert cell
tooltip = d3
.select('body')
.append('div')
.style('position', 'absolute')
.style('z-index', '10')
.style('visibility', 'hidden')
.style('padding', '10px')
.style('background', 'rgba(0,0,0,0.6)')
.style('border-radius', '4px')
.style('color', '#fff');
Insert cell
geoME.features[0]
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