Skip to content

Commit 05fe2f5

Browse files
committed
faceted geo
1 parent 945ae54 commit 05fe2f5

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/marks/geo.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import {computed, shallowRef, onMounted} from "vue";
77

88
const us = shallowRef(null);
99
const earthquakes = shallowRef([]);
10+
const walmarts = shallowRef({type: "FeatureCollection", features: []});
1011
const world = shallowRef(null);
12+
const statemesh = computed(() => us.value ? topojson.mesh(us.value, us.value.objects.states, (a, b) => a !== b) : {type: null});
13+
const nation = computed(() => us.value ? topojson.feature(us.value, us.value.objects.nation) : {type: null});
1114
const counties = computed(() => us.value ? topojson.feature(us.value, us.value.objects.counties).features : []);
1215
const land = computed(() => world.value ? topojson.feature(world.value, world.value.objects.land) : {type: null});
1316

1417
onMounted(() => {
1518
d3.json("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson").then((data) => (earthquakes.value = data));
1619
d3.json("../data/countries-110m.json").then((data) => (world.value = data));
20+
d3.tsv("../data/walmarts.tsv", d3.autoType).then((data) => (walmarts.value = {type: "FeatureCollection", features: data.map((d) => ({type: "Feature", properties: {date: d.date}, geometry: {type: "Point", coordinates: [d.longitude, d.latitude]}}))}));
1721
Promise.all([
1822
d3.json("../data/us-counties-10m.json"),
1923
d3.csv("../data/us-county-unemployment.csv")
@@ -60,11 +64,12 @@ The size of Point and MultiPoint geometries is controlled by the **r** option. F
6064
Plot.plot({
6165
projection: "equirectangular",
6266
style: "overflow: visible;",
67+
r: {transform: (r) => Math.pow(10, r)}, // Richter to amplitude
6368
marks: [
6469
Plot.geo(land, {fill: "currentColor", fillOpacity: 0.2}),
6570
Plot.sphere(),
6671
Plot.geo(earthquakes, {
67-
r: (d) => Math.pow(10, d.properties.mag),
72+
r: (d) => d.properties.mag,
6873
fill: "red",
6974
fillOpacity: 0.2,
7075
stroke: "red",
@@ -124,6 +129,29 @@ Plot.plot({
124129
```
125130
:::
126131

132+
The geo mark supports [faceting](./facets.md). Below, a comic strip of sorts shows the locations of Walmart store openings in past decades.
133+
134+
:::plot defer https://observablehq.com/@observablehq/plot-map-large-multiples
135+
```js
136+
Plot.plot({
137+
margin: 0,
138+
padding: 0,
139+
projection: "albers",
140+
fy: {interval: d3.utcYear.every(10)},
141+
marks: [
142+
Plot.geo(statemesh, {strokeOpacity: 0.2}),
143+
Plot.geo(nation),
144+
Plot.geo(walmarts, {fy: (d) => d.properties.date, r: 1.5, fill: "blue"}),
145+
Plot.axisFy({frameAnchor: "top", dy: 30, tickFormat: (d) => `${d.getUTCFullYear()}’s`})
146+
]
147+
})
148+
```
149+
:::
150+
151+
:::info
152+
This uses the [**interval** scale option](../transforms/interval.md) to bin temporal data into facets by decade.
153+
:::
154+
127155
Lastly, the geo mark is not limited to spherical geometries! [Plot’s projection system](../features/projections.md) includes planar projections, which allow you to work with shapes—such as contours—generated on an arbitrary flat surface.
128156

129157
## Geo options

0 commit comments

Comments
 (0)