Skip to content

Commit 218d90d

Browse files
committed
week 7
1 parent d3463be commit 218d90d

4 files changed

Lines changed: 415 additions & 0 deletions

File tree

observablehq.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ export default {
2626
{ name: "Week 6 Class", path: "/lab_1/week_6_class" },
2727
],
2828
},
29+
{
30+
name: "Lab 2: Subway Staffing",
31+
open: true,
32+
pages: [
33+
{ name: "Week 7 Notes", path: "/lab_2/week_7_notes" },
34+
{ name: "Week 7 Class", path: "/lab_2/week_7_class" },
35+
{ name: "Playing with AI", path: "/lab_2/playing_with_ai" },
36+
],
37+
},
2938
],
3039

3140
// Content to add to the head of the page, e.g. for a favicon:

src/lab_2/playing_with_ai.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
3+
```js
4+
display(flare)
5+
```
6+
<!--
7+
```js
8+
Plot.plot({
9+
marks: [
10+
Plot.dot(diamonds, {x: "carat", y: "price", r: 0.1})
11+
]
12+
})
13+
``` -->
14+
15+
```js
16+
display(Plot.treeNode({
17+
path: "name",
18+
value: "size",
19+
fill: (d) => d.depth,
20+
stroke: "white"
21+
}))
22+
```
23+
24+
25+
26+
```js
27+
const root = d3.hierarchy({children: flare})
28+
.sum(d => d.size);
29+
30+
display(root.descendants())
31+
```
32+
33+
```js
34+
Plot.plot({
35+
marks: [
36+
Plot.dot(flare,
37+
Plot.treeNode(
38+
Plot.tree({path: "name", value: "size"}), {
39+
fill: "node:depth",
40+
stroke: "white",
41+
strokeWidth: 1
42+
}
43+
)
44+
)
45+
],
46+
r: {range: [0, 400]},
47+
color: {scheme: "Spectral", legend: true},
48+
width: 928,
49+
height: 928,
50+
axis: null,
51+
margin: 1
52+
})
53+
```

src/lab_2/week_7_class.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<!-- ## Scales
2+
3+
```js
4+
display(width)
5+
```
6+
7+
```js
8+
Plot.plot({
9+
// width: width,
10+
x: { domain: [0, 100], grid: true },
11+
// y: {},
12+
// marks: []
13+
})
14+
```
15+
16+
```js
17+
Plot.plot({
18+
x: { domain: [100, 0], grid: true }
19+
})
20+
```
21+
22+
```js
23+
Plot.plot({
24+
x: { domain: [ new Date(2020, 0, 0), new Date(2020, 2, 0) ]},
25+
marks: [ Plot.frame() ]
26+
})
27+
``` -->
28+
29+
<!-- ${Plot.plot({ marks: [Plot.frame()]})} -->
30+
31+
<!-- ## Point vs Band
32+
33+
```js
34+
const letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
35+
```
36+
37+
```js
38+
Plot.plot({
39+
x: {
40+
domain: letters,
41+
type: "point",
42+
grid: true
43+
}
44+
})
45+
```
46+
47+
```js
48+
Plot.plot({
49+
x: {
50+
domain: letters,
51+
type: "band",
52+
},
53+
marks: [
54+
Plot.cell(letters, {
55+
x: d => d, // Plot.identity
56+
stroke: "lightgrey"
57+
})
58+
]
59+
})
60+
``` -->
61+
62+
## Marks
63+
64+
```js
65+
view(Inputs.table(diamonds))
66+
```
67+
68+
```js
69+
Plot.plot({
70+
height: 200,
71+
marks: [
72+
Plot.dot(diamonds, {
73+
x: "x",
74+
y: "y",
75+
r: "price",
76+
fill: "lightgrey",
77+
fillOpacity: 0.15,
78+
tip: true
79+
})
80+
]
81+
})
82+
```
83+
84+
```js
85+
Plot.plot({
86+
height: 200,
87+
color: {
88+
scheme: "YlOrRd",
89+
legend: true,
90+
label: "Average price"
91+
},
92+
marks: [
93+
Plot.barY(diamonds,
94+
Plot.groupX(
95+
{ y: "count", fill: "mean" },
96+
{ x: "cut", y: "count", fill: "price" , tip: true }
97+
)
98+
),
99+
],
100+
})
101+
```
102+
103+
104+
<!-- ```js
105+
Plot.plot({
106+
marks: [
107+
Plot.frame(),
108+
Plot.dot(diamonds.filter((d, i) => i < 100), {
109+
x: "color",
110+
y: "cut"
111+
})
112+
]
113+
})
114+
``` -->
115+
116+
```js
117+
Plot.plot({
118+
marks: [
119+
Plot.frame(),
120+
Plot.text(diamonds,
121+
Plot.group(
122+
{ text: "count" },
123+
{ x: "color", y: "cut", text: "count" }
124+
)
125+
)
126+
]
127+
})
128+
```
129+
130+
```js
131+
Plot.plot({
132+
marks: [
133+
Plot.frame(),
134+
Plot.cell(diamonds,
135+
Plot.group(
136+
{ fill: "mean" },
137+
{ x: "color", y: "cut", fill: "price" }
138+
)
139+
)
140+
],
141+
color: {
142+
scheme: "YlOrRd",
143+
legend: true,
144+
label: "Average price"
145+
},
146+
})
147+
```

0 commit comments

Comments
 (0)