Skip to content

Commit 954058a

Browse files
committed
add driving example
1 parent 844181c commit 954058a

File tree

5 files changed

+176
-0
lines changed

5 files changed

+176
-0
lines changed

test/data/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ https://github.com/hemanrobinson/preattentive/blob/a58dd4795d0ee063a38a2d7bf3381
4343
ggplot2 “diamonds” dataset (carat and price columns only)
4444
https://github.com/tidyverse/ggplot2/blob/master/data-raw/diamonds.csv
4545

46+
## driving.csv
47+
Based on Hannah Fairfield’s Driving Shifts Into Reverse
48+
https://archive.nytimes.com/www.nytimes.com/imagepages/2010/05/02/business/02metrics.html
49+
4650
## energy-production.csv
4751
U.S. Energy Information Administration; monthly energy review, primary energy production by source, Jan. 2022
4852
https://www.eia.gov/totalenergy/data/monthly/index.php

test/data/driving.csv

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
side,year,miles,gas
2+
left,1956,3683.6965,2.3829
3+
right,1957,3722.7648,2.4026
4+
bottom,1958,3776.8595,2.2539
5+
top,1959,3912.0962,2.3079
6+
right,1960,3942.1488,2.2658
7+
bottom,1961,3984.2224,2.2526
8+
right,1962,4089.4064,2.2158
9+
bottom,1963,4230.6536,2.1237
10+
bottom,1964,4383.9219,2.1039
11+
bottom,1965,4546.2059,2.1368
12+
top,1966,4681.4425,2.1421
13+
bottom,1967,4837.716,2.1408
14+
right,1968,5048.0841,2.1263
15+
right,1969,5216.3787,2.0737
16+
right,1970,5384.6732,2.0118
17+
bottom,1971,5652.1412,1.9316
18+
bottom,1972,5979.7145,1.8737
19+
right,1973,6160.0301,1.9026
20+
left,1974,5946.6566,2.3447
21+
bottom,1975,6117.9564,2.3079
22+
bottom,1976,6400.4508,2.3237
23+
right,1977,6634.861,2.3592
24+
bottom,1978,6890.308,2.2288
25+
left,1979,6755.0714,2.6829
26+
left,1980,6670.9241,3.2974
27+
right,1981,6743.0503,3.2961
28+
right,1982,6836.2134,2.9197
29+
right,1983,6938.3921,2.6566
30+
right,1984,7127.7235,2.475
31+
right,1985,7326.0706,2.3618
32+
left,1986,7554.4703,1.7605
33+
top,1987,7776.8595,1.7553
34+
bottom,1988,8089.4064,1.6842
35+
left,1989,8395.9428,1.7473
36+
top,1990,8537.1901,1.8763
37+
right,1991,8528.1743,1.7776
38+
right,1992,8675.432,1.6855
39+
left,1993,8843.7265,1.5974
40+
bottom,1994,8906.837,1.5842
41+
bottom,1995,9144.2524,1.5987
42+
top,1996,9183.3208,1.6737
43+
right,1997,9405.71,1.6461
44+
bottom,1998,9577.0098,1.3881
45+
right,1999,9688.2044,1.4987
46+
top,2000,9706.2359,1.8947
47+
left,2001,9685.1991,1.7658
48+
bottom,2002,9802.4042,1.6381
49+
right,2003,9853.4936,1.8592
50+
left,2004,9991.7355,2.1421
51+
left,2005,10054.846,2.5329
52+
right,2006,10030.8039,2.7934
53+
right,2007,10012.7724,2.9487
54+
left,2008,9871.5252,3.3066
55+
bottom,2009,9652.1412,2.3776
56+
left,2010,9592.0361,2.6066

test/output/driving.svg

Lines changed: 95 additions & 0 deletions
Loading

test/plots/driving.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export default async function() {
5+
const driving = await d3.csv("data/driving.csv", d3.autoType);
6+
return Plot.plot({
7+
inset: 10,
8+
grid: true,
9+
x: {
10+
label: "Miles driven (per person-year) →"
11+
},
12+
y: {
13+
label: "↑ Cost of gasoline ($ per gallon)"
14+
},
15+
marks: [
16+
Plot.line(driving, {x: "miles", y: "gas", curve: "catmull-rom", markerMid: "arrow"}),
17+
Plot.text(driving, {filter: d => d.year % 5 === 0, x: "miles", y: "gas", text: d => `${d.year}`, dy: -12})
18+
]
19+
});
20+
}

test/plots/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export {default as decathlon} from "./decathlon.js";
4141
export {default as diamondsCaratPrice} from "./diamonds-carat-price.js";
4242
export {default as diamondsCaratPriceDots} from "./diamonds-carat-price-dots.js";
4343
export {default as documentationLinks} from "./documentation-links.js";
44+
export {default as driving} from "./driving.js";
4445
export {default as empty} from "./empty.js";
4546
export {default as emptyLegend} from "./empty-legend.js";
4647
export {default as emptyX} from "./empty-x.js";

0 commit comments

Comments
 (0)