Public
Edited
Nov 2, 2023
Insert cell
Insert cell
Plot.plot({
height: 600,
insetTop: 90, insetBottom: 60, insetLeft: 20, insetRight: 20,
marginTop: 20,
axis: null,
color: {type: "sequential", legend: true,
range: ["#008080", "#836539"],
label: "Total production of housing by county",
style: {fontSize: 20}, width: 630, ticks: 4},
marks: [
Plot.frame({fill: "black", opacity: 1}),
Plot.hexgrid({fill: "#008080", opacity: .2}),
Plot.hexgrid({fill: "black", opacity: .3, dy: 10}),
Plot.cell(counties.features, {x: d=>d.properties.x, y: d=>d.properties.y, fill: d=>d.properties.totalproduction}),
Plot.hexgrid({fill: "#836539", opacity: .3, dy: 20, stroke: "black"}),
Plot.text(counties.features, {x: d=>d.properties.x, y: d=>d.properties.y, text: d=>d.properties.name, dy: -2, fill: "white", fontSize: 25}),
Plot.text(['New construction'],{x:2, y: 0, dx: -170, dy: -100, fontSize: 48, fill: "#008080", opacity: 1, lineHeight: 1.2, fontWeight: "Bold", lineWidth: 15, textAnchor: "middle"}),
Plot.text(['San\nFrancisco\ncounties'],{x:0, y: 2, dx: 0, dy: 50, fontSize: 35, fill: "#008080", opacity: 1, lineHeight: 1.2, lineWidth: 45, textAnchor: "middle", fontStyle: "italic"}),
Plot.text(['Data: sfgov.org | Design: Deepsha Menghani\nThreads: @IandLoveandData | Mastodon: @Deepsha'],{x:2, y: 3, dx: 70, dy: 80, fontSize: 17, fill: "#008080", opacity: 1, lineHeight: 1.2, lineWidth: 25, textAnchor: "end", fontStyle: "italic"}),
]
})
Insert cell
new_construction_sf.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
new_construction_sf
Select * from new_construction_sf
where year == 2018
Insert cell
import {addTooltips} from "@mkfreeman/plot-tooltip"
Insert cell
import {counties} from "ff0a83b495637684"
Insert cell
function mergeData() {
counties.features = counties.features.filter(feature => {
return new_construction_sf_2018.some(row => row.county === feature.properties.name);
});

counties.features = counties.features.map(feature => {
const matchedState = new_construction_sf_2018.find(row => row.county == feature.properties.name);
if (matchedState) {
feature.properties.totalproduction = matchedState.totalproduction;
feature.properties.x = matchedState.x;
feature.properties.y = matchedState.y;
feature.properties.year = matchedState.year;
}
return feature;
});
}
Insert cell
mergeData()
Insert cell
counties
Insert cell
import {Scrubber} from "@mbostock/scrubber"
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