Public
Edited
Apr 11, 2023
28 forks
Importers
67 stars
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
projection: "albers",
marks: [Plot.geo(nation), Plot.geo(statemesh, { strokeOpacity: 0.2 })]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 960,
height: 600,
projection: "albers",
color: {
legend: true,
label: "Opening year"
},
marks: [
Plot.geo(nation),
Plot.geo(statemesh, {strokeOpacity: 0.2}),
Plot.dot(walmarts, {x: "longitude", y: "latitude", stroke: "date", symbol: "square"})
]
})
Insert cell
Insert cell
Plot.plot({
width: 960,
height: 150,
marginLeft: 0,
marginRight: 0,
projection: "albers",
fx: { tickFormat: (d) => `${d}’s`, padding: 0 },
facet: { data: walmarts, x: (d) => Math.floor(d.date.getUTCFullYear() / 10) * 10 },
marks: [
Plot.geo(statemesh, { clip: "frame", strokeOpacity: 0.1 }),
Plot.dot(walmarts, { x: "longitude", y: "latitude", r: 1, fill: "currentColor" }),
Plot.geo(nation, { clip: "frame" })
]
})
Insert cell
Insert cell
Plot.plot({
width: 960,
height: 600,
projection: "albers",
marks: [
Plot.geo(nation),
Plot.dot(walmarts, {x: "longitude", y: "latitude", fill: "currentColor", r: 1}),
Plot.voronoiMesh(walmarts, {x: "longitude", y: "latitude"})
]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 975,
projection: "albers",
r: {
range: [0, 20]
},
color: {
legend: true,
label: "First year opened",
scheme: "spectral"
},
marks: [
Plot.geo(statemesh, { strokeOpacity: 0.25 }),
Plot.geo(nation),
Plot.dot(
walmarts,
Plot.hexbin(
{ r: "count", fill: "min" },
{ x: "longitude", y: "latitude", fill: "date" }
)
)
]
})
Insert cell
Insert cell
Plot.plot({
width: 960,
height: 600,
projection: "albers",
color: {
scheme: "blues"
},
marks: [
Plot.density(walmarts, {
x: "longitude",
y: "latitude",
bandwidth: 12,
fill: "density"
}),
Plot.dot(walmarts, {
x: "longitude",
y: "latitude",
r: 1,
fill: "currentColor"
}),
Plot.geo(statemesh, { strokeOpacity: 0.3 }),
Plot.geo(nation)
]
})
Insert cell
Insert cell
Plot.plot({
projection: "albers",
marks: [
Plot.geo(statemesh, { clip: "frame", strokeOpacity: 0.1 }),
Plot.geo(nation, { clip: "frame" }),
Plot.text(
states.features,
Plot.centroid({
text: (d) => d.properties.name,
textAnchor: "middle",
stroke: "white",
fill: "black"
})
)
]
})
Insert cell
Insert cell
winds = {
// id is the county’s fips code; we index it in a fast lookup table
const lookup = d3.index(counties.features, (d) => d.id);
return Plot.plot({
projection: "albers-usa",
width: 975,
marks: [
Plot.geo(statemesh, { strokeWidth: 0.75 }),
Plot.geo(nation),
Plot.vector(
elections,
Plot.centroid({
filter: (d) => d.votes > 0,
anchor: "start",
geometry: (d) => lookup.get(d.fips),
sort: (d) => Math.abs(+d.results_trumpd - +d.results_bidenj),
stroke: (d) => +d.results_trumpd > +d.results_bidenj ? "red" : "blue",
length: (d) => Math.sqrt(Math.abs(+d.margin2020 * +d.votes)),
rotate: (d) => (+d.results_bidenj < +d.results_trumpd ? 60 : -60)
})
)
]
});
}
Insert cell
Insert cell
Insert cell
Insert cell
walmarts = FileAttachment("walmarts.tsv").tsv({typed: true})
Insert cell
elections = FileAttachment("us-presidential-election-2020.csv").csv()
Insert cell
us = FileAttachment("us-counties-10m.json").json()
Insert cell
nation = topojson.feature(us, us.objects.nation)
Insert cell
states = topojson.feature(us, us.objects.states)
Insert cell
statemesh = topojson.mesh(us, us.objects.states, (a, b) => a !== b)
Insert cell
counties = topojson.feature(us, us.objects.counties)
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