1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
|
WEBVTT
NOTE Introduction
00:00:00.110 --> 00:00:02.705
Welcome! My name is Lukas, and today
00:00:02.706 --> 00:00:05.090
we will use gnuplot to draw graphs
00:00:05.160 --> 00:00:07.147
and organise the work in Emacs,
00:00:07.148 --> 00:00:09.010
a text editor, using Org mode.
00:00:09.210 --> 00:00:11.066
That lets us keep data,
00:00:11.067 --> 00:00:13.850
code and explanation in one document
00:00:13.880 --> 00:00:16.278
and build figures we can understand,
00:00:16.279 --> 00:00:17.380
revise and share.
00:00:20.520 --> 00:00:22.275
A figure may need to be corrected
00:00:22.276 --> 00:00:24.340
months later or rebuilt by someone else.
00:00:24.920 --> 00:00:26.757
That raises two questions:
00:00:26.758 --> 00:00:28.799
will our tools still serve us,
00:00:28.800 --> 00:00:30.005
and will someone
00:00:30.006 --> 00:00:31.919
understand how we use them?
NOTE ROOT: Robust, Open, Ongoing and Time-tested
00:00:31.920 --> 00:00:34.945
I've developed two frameworks around those
00:00:34.946 --> 00:00:37.620
questions: ROOT for technology choices
00:00:38.040 --> 00:00:40.220
and SHAPE for workflows.
00:00:40.410 --> 00:00:42.581
ROOT concerns the tools,
00:00:42.582 --> 00:00:44.839
so that is where we start.
00:00:44.840 --> 00:00:46.964
The name stands for Robust,
00:00:46.965 --> 00:00:49.239
Open, Ongoing and Time-tested.
00:00:49.240 --> 00:00:52.055
These criteria help us assess whether we
00:00:52.056 --> 00:00:54.940
can inspect failures, understand and reuse
00:00:55.130 --> 00:00:57.666
the technology, keep using and adapting
00:00:57.667 --> 00:01:00.140
it, and draw on established experience.
00:01:00.310 --> 00:01:02.269
For gnuplot, readable scripts,
00:01:02.270 --> 00:01:04.236
continuing development and decades
00:01:04.237 --> 00:01:06.259
of use give us reasons to choose it.
NOTE SHAPE: Structure, Harmonise, Automate, Propagate, Evaluate
00:01:06.260 --> 00:01:08.324
SHAPE concerns how we organise
00:01:08.325 --> 00:01:10.189
the work around those tools.
00:01:10.190 --> 00:01:12.763
It brings together five principles:
00:01:12.764 --> 00:01:15.479
structure stages, harmonise handovers,
00:01:15.480 --> 00:01:18.905
automate actions, propagate provenance,
00:01:18.906 --> 00:01:20.959
and evaluate explicitly.
00:01:20.960 --> 00:01:23.561
We look at this next because a dependable
00:01:23.562 --> 00:01:25.419
tool still needs clear inputs,
00:01:25.420 --> 00:01:26.425
agreed meanings,
00:01:26.426 --> 00:01:28.199
recorded decisions and checks.
00:01:28.200 --> 00:01:31.000
These principles give us things to look
00:01:31.001 --> 00:01:33.799
for when we watch the practical example.
NOTE The dataset
00:01:33.800 --> 00:01:35.687
For that example, we will use
00:01:35.688 --> 00:01:37.699
a teaching dataset of passengers
00:01:37.700 --> 00:01:39.947
and crew aboard the Titanic,
00:01:39.948 --> 00:01:41.419
which sank in 1912.
00:01:41.420 --> 00:01:44.003
It records class or crew membership,
00:01:44.004 --> 00:01:45.539
sex, age and survival.
00:01:45.540 --> 00:01:48.083
This lets us ask a simple question:
00:01:48.084 --> 00:01:50.979
crew had more survivors than first class,
00:01:50.980 --> 00:01:54.069
but did they have a higher survival rate?
00:01:54.070 --> 00:01:55.988
We'll explore that question
00:01:55.989 --> 00:01:57.289
in an Org notebook,
00:01:57.290 --> 00:01:59.050
using gnuplot to draw
00:01:59.051 --> 00:02:00.889
and revise the figures.
00:02:00.890 --> 00:02:01.966
So our route is:
00:02:01.967 --> 00:02:03.740
introduce the tool criteria,
00:02:03.990 --> 00:02:06.008
establish the workflow principles,
00:02:06.009 --> 00:02:08.199
then put both into practice with data.
NOTE Org Notebook
00:02:08.200 --> 00:02:10.078
Let's switch to our Org notebook
00:02:10.079 --> 00:02:12.069
in Emacs and start the live coding.
00:02:12.070 --> 00:02:14.058
I'll change a little code, run it
00:02:14.059 --> 00:02:16.279
and we'll look at the result together.
00:02:16.280 --> 00:02:17.829
The notebook keeps data,
00:02:17.830 --> 00:02:19.750
code and pictures in one place.
00:02:19.800 --> 00:02:22.907
First, let's open the raw CSV,
00:02:22.908 --> 00:02:24.209
the raw data.
00:02:24.210 --> 00:02:26.719
We'll turn it into a small table
00:02:26.720 --> 00:02:28.999
and build our plot from there.
00:02:29.000 --> 00:02:30.259
Our question is:
00:02:30.260 --> 00:02:32.571
did crew have a better chance
00:02:32.572 --> 00:02:35.730
of surviving than first-class passengers?
00:02:36.670 --> 00:02:39.715
Each row is one person here; survival
00:02:39.716 --> 00:02:42.759
is one for survived and zero for died.
00:02:42.760 --> 00:02:45.069
There are 2,207 people
00:02:45.070 --> 00:02:47.580
in this teaching dataset,
00:02:47.770 --> 00:02:50.272
and that's our SHAPE structure:
00:02:50.273 --> 00:02:53.399
a question and a route through the work.
00:02:53.400 --> 00:02:56.549
Next, we let AWK count the groups.
00:02:56.550 --> 00:02:58.786
Let's turn all those rows
00:02:58.787 --> 00:03:00.849
into four useful totals.
00:03:00.850 --> 00:03:03.157
We'll run this AWK block and look
00:03:03.158 --> 00:03:05.940
at the table it puts straight underneath.
00:03:06.680 --> 00:03:10.139
The commas tell AWK where each field ends.
00:03:10.140 --> 00:03:11.299
We skip the header,
00:03:11.300 --> 00:03:14.151
use the first field to identify the group
00:03:14.152 --> 00:03:16.459
and count one person for each row.
00:03:16.460 --> 00:03:18.779
Then we add the fourth field.
00:03:18.780 --> 00:03:20.752
Because it's zero or one,
00:03:20.753 --> 00:03:23.179
that sum gives us the survivors.
00:03:23.180 --> 00:03:25.243
Subtract survivors from everyone
00:03:25.244 --> 00:03:27.370
aboard and we have the deaths too.
00:03:28.200 --> 00:03:29.424
The last loop puts
00:03:29.425 --> 00:03:31.229
the groups in a fixed order.
00:03:31.230 --> 00:03:33.300
There we go: four rows
00:03:33.301 --> 00:03:35.549
with the numbers we need.
00:03:35.550 --> 00:03:37.729
This is our SHAPE handover:
00:03:37.730 --> 00:03:40.919
a small table with clear column meanings.
00:03:40.920 --> 00:03:44.040
For now, it's just an AWK result.
00:03:44.140 --> 00:03:45.946
But next, we'll add the name
00:03:45.947 --> 00:03:48.500
and plotting lines around the same table.
NOTE Making our first plot
00:03:49.000 --> 00:03:50.478
Now let's make our first
00:03:50.479 --> 00:03:51.719
plot from this table.
00:03:51.720 --> 00:03:54.099
We'll add its name and plotting lines,
00:03:54.100 --> 00:03:55.706
run the plot and then put a link
00:03:55.707 --> 00:03:57.410
to the saved picture underneath it.
00:03:58.280 --> 00:04:00.240
The name is demo-class-counts,
00:04:00.241 --> 00:04:02.580
so we can use this table again later.
00:04:03.320 --> 00:04:06.422
`ind:1` takes the group names from the first
00:04:06.423 --> 00:04:09.380
column, `and deps:(3)` picks the survivors.
00:04:10.040 --> 00:04:13.109
I run `org-plot/gnuplot` inside the table.
00:04:13.110 --> 00:04:15.739
That writes our SVG file.
00:04:15.740 --> 00:04:19.009
To show it here, I add a file link below
00:04:19.010 --> 00:04:21.879
the table and refresh inline images.
00:04:21.880 --> 00:04:24.119
There are our four bars.
00:04:24.120 --> 00:04:26.675
Keeping that table and picture together
00:04:26.676 --> 00:04:29.229
makes the SHAPE handover easy to follow.
00:04:29.230 --> 00:04:32.559
Crew is slightly ahead of first class.
00:04:32.560 --> 00:04:34.217
Next, let's check how many
00:04:34.218 --> 00:04:36.119
people each group started with.
00:04:36.120 --> 00:04:39.859
Before we read too much into those bars,
00:04:39.860 --> 00:04:43.610
let's try column 2: everyone aboard.
00:04:43.620 --> 00:04:45.024
I change `deps:(3)`
00:04:45.025 --> 00:04:47.130
to `deps:(2)` and plot again.
00:04:48.680 --> 00:04:50.169
Crew had 890 people.
00:04:50.170 --> 00:04:53.499
First class had 324.
00:04:53.500 --> 00:04:56.095
Similar survivor counts came
00:04:56.096 --> 00:04:58.959
from very different group sizes.
00:04:58.960 --> 00:05:01.419
I put `deps:(3)` back and redraw.
NOTE Using a Gnuplot block
00:05:01.420 --> 00:05:04.281
Next, we use a Gnuplot block so we
00:05:04.282 --> 00:05:06.979
can develop the figure ourselves.
00:05:06.980 --> 00:05:09.404
Now let's move from the table's plot
00:05:09.405 --> 00:05:11.959
instructions to a Gnuplot source block.
00:05:11.960 --> 00:05:13.588
Those plot lines were
00:05:13.589 --> 00:05:15.289
handy for a quick look.
00:05:15.290 --> 00:05:17.717
Next, we calculate percentages,
00:05:17.718 --> 00:05:20.599
reuse a style and draw several series.
00:05:20.600 --> 00:05:22.902
A source block gives us one place
00:05:22.903 --> 00:05:25.069
to read and edit those commands.
00:05:25.070 --> 00:05:27.500
We'll keep the same table
00:05:27.501 --> 00:05:29.467
and the same SVG file.
00:05:29.468 --> 00:05:32.100
The `:var` header supplies our named table.
00:05:32.600 --> 00:05:34.804
`:file` says where the picture goes,
00:05:34.805 --> 00:05:36.619
and `term` chooses the format.
00:05:36.620 --> 00:05:38.519
With the file-result
00:05:38.520 --> 00:05:40.689
settings we've prepared,
00:05:40.690 --> 00:05:43.021
Babel adds or updates the result
00:05:43.022 --> 00:05:44.999
link below the block for us.
00:05:45.000 --> 00:05:47.109
That's the automation part of SHAPE:
00:05:47.110 --> 00:05:49.474
we can rerun one recipe and keep
00:05:49.475 --> 00:05:51.479
its result together with it.
00:05:51.480 --> 00:05:55.419
Let's start with just plot data using 3.
00:05:55.420 --> 00:05:58.430
Run the block and we get four points:
00:05:58.431 --> 00:06:00.490
the survivor counts again.
00:06:00.920 --> 00:06:03.110
We'll keep building in this block.
NOTE Group names
00:06:03.290 --> 00:06:06.100
Next, let's put the group names back.
00:06:07.080 --> 00:06:08.370
Let's make those four
00:06:08.371 --> 00:06:09.659
points easier to read.
00:06:09.660 --> 00:06:11.399
We'll add the group names,
00:06:11.400 --> 00:06:13.032
leave some room at the sides
00:06:13.033 --> 00:06:14.890
and start the vertical axis at 0.
00:06:15.640 --> 00:06:17.285
In the using expression,
00:06:17.286 --> 00:06:19.259
column 0 means the row number,
00:06:19.260 --> 00:06:21.276
column 3 gives us the height
00:06:21.277 --> 00:06:23.849
and xtic(1) supplies the group names.
00:06:23.850 --> 00:06:26.919
notitle removes the automatic legend.
00:06:26.920 --> 00:06:28.396
We don't need a legend
00:06:28.397 --> 00:06:30.129
for a single set of points.
00:06:30.130 --> 00:06:32.342
Run the block again and the picture
00:06:32.343 --> 00:06:33.940
updates in the same place.
00:06:34.440 --> 00:06:35.889
Now we can tell which point
00:06:35.890 --> 00:06:37.079
belongs to which group.
00:06:37.080 --> 00:06:40.420
That's the same SHAPE handover idea.
00:06:40.760 --> 00:06:42.679
Make the columns and labels clear.
NOTE Adding bars
00:06:42.680 --> 00:06:44.958
Next, we'll turn them into bars
00:06:44.959 --> 00:06:47.380
and give the chart a bit of style.
00:06:49.000 --> 00:06:51.209
Let's turn these points into filled bars,
00:06:51.210 --> 00:06:52.410
then give the chart
00:06:52.411 --> 00:06:53.850
a title and clear units.
00:06:54.280 --> 00:06:56.299
We'll put the appearance settings
00:06:56.300 --> 00:06:58.199
in a small style block above it.
00:06:58.200 --> 00:06:59.709
`boxwidth` controls the width.
00:06:59.710 --> 00:07:02.480
The `fill` setting colours the bars, and
00:07:02.481 --> 00:07:05.249
the `linetype` setting gives us our blue.
00:07:05.250 --> 00:07:07.711
The plot block keeps the title and the
00:07:07.712 --> 00:07:09.920
label saying we're counting people.
00:07:09.960 --> 00:07:12.116
The little Noweb reference pulls
00:07:12.117 --> 00:07:14.599
in the style whenever we run the plot.
00:07:14.600 --> 00:07:17.286
So after changing the style, I run
00:07:17.287 --> 00:07:20.279
the plot again and see the result here.
00:07:20.280 --> 00:07:23.479
That's another bit of SHAPE automation.
00:07:23.480 --> 00:07:25.479
Reuse one definition.
00:07:25.480 --> 00:07:28.219
Same four values, much easier to read.
NOTE Tidying up
00:07:28.220 --> 00:07:30.570
Let's tidy up the frame next.
00:07:31.560 --> 00:07:33.131
Before we add more data,
00:07:33.132 --> 00:07:35.710
let's tidy up the borders and tick marks.
00:07:36.120 --> 00:07:38.054
We'll keep the bottom and left
00:07:38.055 --> 00:07:39.739
edges and add a light grid.
00:07:39.740 --> 00:07:42.779
Each border has a value:
00:07:42.780 --> 00:07:45.095
Bottom is 1, left is 2,
00:07:45.096 --> 00:07:47.409
top is 4 and right is 8.
00:07:47.410 --> 00:07:49.479
Add the sides you want.
00:07:49.480 --> 00:07:52.981
1 + 2 gives 3, so set border
00:07:52.982 --> 00:07:55.879
3 keeps bottom and left.
00:07:55.880 --> 00:07:58.402
The ticks have separate settings:
00:07:58.403 --> 00:08:01.369
nomirror removes their copies at the top
00:08:01.370 --> 00:08:03.090
and right, and out points
00:08:03.091 --> 00:08:05.669
the remaining ticks away from the bars.
00:08:05.670 --> 00:08:09.140
The grid goes behind the data.
00:08:09.150 --> 00:08:11.029
Our small SHAPE check here is
00:08:11.030 --> 00:08:13.159
whether the scale is easy to read.
NOTE Additional series
00:08:13.160 --> 00:08:14.751
Now we are ready to bring
00:08:14.752 --> 00:08:16.649
in the people who died as well.
00:08:16.650 --> 00:08:19.369
Let's show survivors and deaths together.
00:08:19.370 --> 00:08:20.957
We use two bars per group,
00:08:20.958 --> 00:08:23.309
with a legend so we can tell them apart.
00:08:23.310 --> 00:08:25.388
We switch to clustered histograms
00:08:25.389 --> 00:08:27.650
and give the plot command two series.
00:08:27.820 --> 00:08:29.690
One takes the survivor column;
00:08:29.691 --> 00:08:31.319
the other takes the deaths.
00:08:31.320 --> 00:08:32.820
Blue means survived
00:08:32.821 --> 00:08:34.920
and the pale bars mean died.
00:08:35.130 --> 00:08:36.659
Putting the bars side by side
00:08:36.660 --> 00:08:38.629
makes it easy to compare the two
00:08:38.630 --> 00:08:40.239
outcomes within each group.
00:08:40.240 --> 00:08:42.391
I'll keep the legend above the chart
00:08:42.392 --> 00:08:44.020
so it leaves the data clear.
00:08:44.600 --> 00:08:46.441
We can already see a different
00:08:46.442 --> 00:08:47.629
story in each group.
NOTE Stacking outcomes
00:08:47.630 --> 00:08:49.776
So next we'll stack these
00:08:49.777 --> 00:08:52.169
same bars to show the totals.
00:08:52.170 --> 00:08:54.771
Let's stack those two outcomes and see
00:08:54.772 --> 00:08:57.039
what happens to the overall shape.
00:08:57.040 --> 00:08:59.102
We only need to change the histogram
00:08:59.103 --> 00:09:01.220
layout and update the title and units.
00:09:01.880 --> 00:09:04.679
Now each full bar is everyone aboard:
00:09:04.680 --> 00:09:06.123
the blue part is survivors
00:09:06.124 --> 00:09:07.620
and the pale part is deaths.
00:09:08.110 --> 00:09:10.335
A useful SHAPE check is that those
00:09:10.336 --> 00:09:12.370
parts add up to the group total.
00:09:13.000 --> 00:09:15.399
Look at crew compared with first class.
00:09:15.400 --> 00:09:17.468
The blue parts are quite similar,
00:09:17.469 --> 00:09:19.719
but the full crew bar is much taller.
00:09:19.720 --> 00:09:23.719
Crew had 890 people; first class had 324.
00:09:23.720 --> 00:09:26.354
So a similar number of survivors came
00:09:26.355 --> 00:09:28.849
from very different starting groups.
NOTE Percentages
00:09:28.850 --> 00:09:31.863
Next we'll put each group on a percentage
00:09:31.864 --> 00:09:34.589
scale to make that comparison clearer.
00:09:34.590 --> 00:09:36.223
Now let's turn those
00:09:36.224 --> 00:09:38.090
counts into percentages.
00:09:38.110 --> 00:09:40.241
We write one small rate function
00:09:40.242 --> 00:09:42.759
and use it for both parts of the stack.
00:09:42.760 --> 00:09:45.817
The function takes a count, divides it by
00:09:45.818 --> 00:09:48.729
the number aboard and multiplies by 100.
00:09:48.730 --> 00:09:50.244
Writing it once saves us
00:09:50.245 --> 00:09:51.879
repeating that calculation.
00:09:51.880 --> 00:09:55.110
That's the automate-actions idea in SHAPE.
00:09:55.290 --> 00:09:57.110
Then we use it for the survivor
00:09:57.111 --> 00:09:58.759
column and the deaths column,
00:09:58.760 --> 00:10:01.430
and set the axis from 0 to 100.
00:10:01.610 --> 00:10:03.537
Run the block and every stack
00:10:03.538 --> 00:10:05.079
reaches the same height.
00:10:05.080 --> 00:10:06.912
The blue part now takes up much
00:10:06.913 --> 00:10:08.629
more of first class than crew.
00:10:08.630 --> 00:10:10.680
That's the difference we couldn't
00:10:10.681 --> 00:10:12.549
see from survivor counts alone.
00:10:12.550 --> 00:10:15.309
Let's keep just those survival rates next.
00:10:15.310 --> 00:10:17.637
Let's make the answer easier to pick
00:10:17.638 --> 00:10:20.089
out by showing only the survival rates.
00:10:20.090 --> 00:10:22.143
We'll go back to simple bars
00:10:22.144 --> 00:10:24.480
and keep the full 0 to 100 scale.
00:10:25.390 --> 00:10:27.590
We remove the histogram settings
00:10:27.591 --> 00:10:29.389
and the two-outcome legend.
00:10:29.390 --> 00:10:31.459
The rate function stays and we use
00:10:31.460 --> 00:10:33.469
it to calculate each bar's height.
00:10:33.470 --> 00:10:35.872
I also put percent signs on the tick
00:10:35.873 --> 00:10:38.599
labels so the units are clear at a glance.
00:10:38.600 --> 00:10:41.709
First class is highest; crew is lowest.
00:10:41.710 --> 00:10:44.349
We've changed from asking how many
00:10:44.350 --> 00:10:47.289
survived to asking what share survived.
00:10:47.290 --> 00:10:49.114
That's our SHAPE check:
00:10:49.115 --> 00:10:51.850
does the measure match our question?
NOTE Leaving out a group
00:10:52.600 --> 00:10:54.562
Next I'll show you how to leave out
00:10:54.563 --> 00:10:56.469
a group without changing the table.
00:10:56.470 --> 00:10:58.254
Let's look at passengers
00:10:58.255 --> 00:10:59.539
only for a moment.
00:10:59.540 --> 00:11:01.223
We'll hide crew in this view
00:11:01.224 --> 00:11:03.140
and leave the source table alone.
00:11:04.360 --> 00:11:05.352
Inside using,
00:11:05.353 --> 00:11:07.479
we check the name in column 1.
00:11:07.480 --> 00:11:11.879
If it's Crew, we return 1 divided by 0.
00:11:11.880 --> 00:11:13.619
Gnuplot treats that as
00:11:13.620 --> 00:11:16.039
an undefined value and skips it.
00:11:16.040 --> 00:11:17.293
For the other rows,
00:11:17.294 --> 00:11:19.109
we keep the rate calculation.
00:11:19.110 --> 00:11:21.275
We also adjust the horizontal range
00:11:21.276 --> 00:11:23.200
and say passengers in the title.
00:11:23.250 --> 00:11:25.428
That's a small SHAPE check:
00:11:25.429 --> 00:11:28.539
the title should tell us who's included.
00:11:28.540 --> 00:11:31.118
There are our three passenger classes
00:11:31.119 --> 00:11:33.289
with their original percentages.
00:11:33.290 --> 00:11:35.483
Next we'll bring crew back and write
00:11:35.484 --> 00:11:37.439
the actual values above the bars.
00:11:37.440 --> 00:11:39.837
That way nobody has to estimate
00:11:39.838 --> 00:11:41.709
the values from the axis.
00:11:41.710 --> 00:11:44.009
We restore the original range
00:11:44.010 --> 00:11:45.916
and add another use of the same table
00:11:45.917 --> 00:11:46.919
to the plot command.
00:11:46.920 --> 00:11:49.706
This time it supplies text
00:11:49.707 --> 00:11:52.079
at each bar's position.
00:11:52.080 --> 00:11:54.507
sprintf formats the number to one
00:11:54.508 --> 00:11:57.220
decimal place and adds a percent sign.
00:11:57.720 --> 00:12:00.366
Both the bar and its label use our rate
00:12:00.367 --> 00:12:02.880
function, so they agree automatically.
00:12:04.040 --> 00:12:06.259
That's SHAPE automation saving
00:12:06.260 --> 00:12:08.549
us from copying numbers by hand.
00:12:08.550 --> 00:12:11.354
Now we can read about 62%
00:12:11.355 --> 00:12:15.129
for first class and 23.7% for crew.
NOTE Digging into the details
00:12:15.130 --> 00:12:17.295
Let's see what those group
00:12:17.296 --> 00:12:19.300
averages might be hiding.
00:12:19.960 --> 00:12:21.437
Let's split that comparison
00:12:21.438 --> 00:12:22.439
into women and men.
00:12:22.440 --> 00:12:24.680
We'll connect a second named table
00:12:24.681 --> 00:12:26.280
to the same Gnuplot block
00:12:26.470 --> 00:12:29.079
and draw the two rates beside each other.
00:12:29.080 --> 00:12:32.113
I add `sex=demo-class-sex`
00:12:32.114 --> 00:12:33.820
to the `:var` header.
00:12:33.980 --> 00:12:35.799
That table comes from the same CSV
00:12:35.800 --> 00:12:38.877
but keeps separate counts for the recorded
00:12:38.878 --> 00:12:41.309
sex categories including children.
00:12:41.310 --> 00:12:42.948
Same SHAPE handover:
00:12:42.949 --> 00:12:45.989
we need to know what each column means.
00:12:45.990 --> 00:12:47.978
For each series we divide
00:12:47.979 --> 00:12:50.959
its survivors by its own number aboard.
00:12:50.960 --> 00:12:53.719
Run it and we get two bars per group.
00:12:53.720 --> 00:12:56.459
Women have higher survival rates
00:12:56.460 --> 00:12:58.119
in every group here.
00:12:58.120 --> 00:13:00.318
So the overall group rate leaves
00:13:00.319 --> 00:13:02.049
out quite a bit of detail.
00:13:02.050 --> 00:13:04.258
Next, we'll try a different way
00:13:04.259 --> 00:13:06.189
to show the same comparison.
00:13:06.190 --> 00:13:08.617
Let's keep those two calculations
00:13:08.618 --> 00:13:10.829
and try points instead of bars.
00:13:10.830 --> 00:13:12.963
It's a quick way to see how much
00:13:12.964 --> 00:13:15.549
the choice of chart changes the picture.
00:13:15.550 --> 00:13:18.389
We remove the histogram settings and use
00:13:18.390 --> 00:13:21.160
a circle for women and a square for men.
00:13:21.350 --> 00:13:24.789
Each pair sits at the same group position.
00:13:24.790 --> 00:13:27.298
Our SHAPE check is whether this view
00:13:27.299 --> 00:13:29.739
makes the comparison easier to read.
00:13:29.740 --> 00:13:31.650
The shapes help us tell them
00:13:31.651 --> 00:13:33.559
apart as well as the colours.
00:13:33.560 --> 00:13:35.281
We can still see the gap
00:13:35.282 --> 00:13:36.589
within every group,
00:13:36.590 --> 00:13:38.754
and the common percentage scale
00:13:38.755 --> 00:13:40.580
lets us compare groups too.
00:13:40.920 --> 00:13:42.058
That's another view
00:13:42.059 --> 00:13:44.279
from the same table and the same block.
NOTE Overall group rates
00:13:44.280 --> 00:13:47.486
Let's finish with the overall
00:13:47.487 --> 00:13:49.409
group rates again.
00:13:49.410 --> 00:13:51.346
We'll bring back the four labelled
00:13:51.347 --> 00:13:52.839
bars and add a source line,
00:13:52.840 --> 00:13:54.578
so the saved figure makes
00:13:54.579 --> 00:13:56.449
sense outside this notebook.
00:13:56.450 --> 00:13:58.414
We remove the women and men
00:13:58.415 --> 00:14:00.519
table from the variable header
00:14:00.520 --> 00:14:02.099
and use our original
00:14:02.100 --> 00:14:03.979
class-counts table again.
00:14:03.980 --> 00:14:05.790
Then we add the dataset
00:14:05.791 --> 00:14:07.300
version and its DOI.
00:14:07.640 --> 00:14:09.820
That's the provenance part of SHAPE:
00:14:10.010 --> 00:14:11.643
someone can trace this
00:14:11.644 --> 00:14:13.559
picture back to its source.
00:14:13.560 --> 00:14:16.080
The subgroup comparison showed that there
00:14:16.081 --> 00:14:18.359
are differences inside each group too,
00:14:18.360 --> 00:14:21.319
so we'll be careful about what we claim.
00:14:21.320 --> 00:14:23.148
These are the overall
00:14:23.149 --> 00:14:25.060
rates in this snapshot.
NOTE Checking
00:14:26.120 --> 00:14:28.010
Next let's check the total
00:14:28.011 --> 00:14:29.199
before we export.
00:14:29.200 --> 00:14:32.160
We'll also check that the shared style
00:14:32.161 --> 00:14:34.969
still updates when we rerun the plot.
00:14:34.970 --> 00:14:38.015
The stars in the stats ranges tell Gnuplot
00:14:38.016 --> 00:14:40.919
to use all the data for this calculation.
00:14:40.920 --> 00:14:43.053
Otherwise our percentage axis
00:14:43.054 --> 00:14:45.399
would leave out counts above 100.
00:14:45.400 --> 00:14:48.409
This keeps the chart at 0 to 100,
00:14:48.410 --> 00:14:50.805
while stats adds up all
00:14:50.806 --> 00:14:53.399
four survivor counts: 711.
00:14:53.400 --> 00:14:54.797
We use that result
00:14:54.798 --> 00:14:56.929
in a small label so the total
00:14:56.930 --> 00:14:59.575
comes from the table rather than from
00:14:59.576 --> 00:15:02.219
a number we've typed into the picture.
00:15:02.220 --> 00:15:04.793
Now I'll briefly change the shared
00:15:04.794 --> 00:15:06.999
colour and run the plot again.
00:15:07.000 --> 00:15:09.709
There's the colour change.
00:15:09.710 --> 00:15:12.589
Restore it and rerun: we're back to blue.
00:15:12.590 --> 00:15:14.590
Our style connection works,
00:15:14.591 --> 00:15:17.589
and the total agrees with the input check.
00:15:17.590 --> 00:15:20.437
That's SHAPE's evaluate-explicitly idea,
00:15:20.438 --> 00:15:22.660
with a concrete number to check.
NOTE Saving as PDF
00:15:24.110 --> 00:15:25.862
Next, we save the finished
00:15:25.863 --> 00:15:27.159
figure as a PDF too.
00:15:27.160 --> 00:15:29.659
We already have the SVG,
00:15:29.660 --> 00:15:32.120
so we'll change the output options
00:15:32.121 --> 00:15:34.369
and keep the plot code as it is.
00:15:34.370 --> 00:15:36.280
In the header, I change
00:15:36.281 --> 00:15:38.350
the filename to end in PDF
00:15:38.390 --> 00:15:41.189
and choose pdfcairo as the terminal.
00:15:41.190 --> 00:15:43.550
Run the block, open the file,
00:15:43.551 --> 00:15:45.360
and there's our figure.
00:15:45.960 --> 00:15:47.475
Then I restore the SVG
00:15:47.476 --> 00:15:49.319
options for the inline view.
00:15:49.320 --> 00:15:51.489
Keeping the recipe,
00:15:51.490 --> 00:15:53.759
source and export together carries
00:15:53.760 --> 00:15:55.639
our SHAPE provenance forward.
00:15:55.640 --> 00:15:58.388
We can now answer our original question:
00:15:58.389 --> 00:16:00.600
crew had slightly more survivors,
00:16:00.810 --> 00:16:02.836
but a much lower survival rate
00:16:02.837 --> 00:16:05.060
than first class in this snapshot.
00:16:05.400 --> 00:16:07.658
We've got the data, the calculation
00:16:07.659 --> 00:16:09.540
and the saved result together.
NOTE What else can Gnuplot do?
00:16:11.240 --> 00:16:13.290
Now let's spend a few minutes
00:16:13.291 --> 00:16:15.749
looking at what else Gnuplot can do.
00:16:15.750 --> 00:16:17.929
Let's start with three views together.
00:16:17.930 --> 00:16:19.213
I'll show the prepared
00:16:19.214 --> 00:16:20.329
code and the result,
00:16:20.330 --> 00:16:22.050
and we'll just look at what
00:16:22.051 --> 00:16:23.340
the picture tells us.
00:16:23.510 --> 00:16:25.753
On the left, the stacks show
00:16:25.754 --> 00:16:27.919
how many people were aboard.
00:16:27.920 --> 00:16:29.060
In the middle,
00:16:29.061 --> 00:16:31.719
the percentages change the ranking.
00:16:31.720 --> 00:16:34.088
On the right, the connected dots
00:16:34.089 --> 00:16:36.960
compare women and men within each group.
00:16:36.990 --> 00:16:39.020
Putting them together helps us
00:16:39.021 --> 00:16:40.919
see how the questions relate.
00:16:40.920 --> 00:16:43.485
Each panel has a clear job
00:16:43.486 --> 00:16:46.050
just like our SHAPE stages.
00:16:46.250 --> 00:16:48.322
Next, let's look at who made
00:16:48.323 --> 00:16:50.110
up the population aboard.
00:16:51.400 --> 00:16:54.039
This one is about the size of each group.
00:16:54.040 --> 00:16:56.406
Crew makes up about 40%
00:16:56.407 --> 00:16:58.970
and third class about 32%.
00:17:00.200 --> 00:17:03.229
First and second class make up the rest.
00:17:03.230 --> 00:17:05.575
The names and percentages sit right
00:17:05.576 --> 00:17:07.919
in the picture so it's easy to read.
00:17:07.920 --> 00:17:11.316
These slices describe who was aboard; the
00:17:11.317 --> 00:17:14.469
survival rates are a separate question.
00:17:14.470 --> 00:17:16.743
Next, we'll try showing
00:17:16.744 --> 00:17:19.489
several measures in one view.
00:17:19.490 --> 00:17:21.860
So let's try a spider plot.
00:17:22.360 --> 00:17:25.051
It gives each group a shape by placing
00:17:25.052 --> 00:17:27.189
several measures on the spokes.
00:17:27.190 --> 00:17:30.309
Each outline is one group and every
00:17:30.310 --> 00:17:32.909
spoke uses a percentage scale.
00:17:32.910 --> 00:17:34.509
You can follow an outline
00:17:34.510 --> 00:17:37.020
around to see that group's profile
00:17:37.021 --> 00:17:39.459
or compare groups along one spoke.
00:17:39.460 --> 00:17:41.220
The overall shape can
00:17:41.221 --> 00:17:43.220
help us spot differences.
00:17:43.640 --> 00:17:45.328
But the area inside it
00:17:45.329 --> 00:17:46.869
isn't a single score.
00:17:46.870 --> 00:17:49.965
Next, we'll return to class and sex
00:17:49.966 --> 00:17:52.889
and read the rates through colour.
00:17:52.890 --> 00:17:55.659
So let's look at the heatmap.
00:17:55.660 --> 00:17:58.055
The groups run down the side,
00:17:58.056 --> 00:18:01.250
and women and men have separate columns.
00:18:01.360 --> 00:18:03.589
The colour gives us a quick impression,
00:18:03.590 --> 00:18:05.988
and the text keeps the percentages
00:18:05.989 --> 00:18:07.289
and counts visible.
00:18:07.290 --> 00:18:10.865
Look at crew: the women's rate comes from
00:18:10.866 --> 00:18:14.440
23 people, while the men's comes from 867.
00:18:14.550 --> 00:18:16.488
Now let's bring age into
00:18:16.489 --> 00:18:18.039
the picture as well.
00:18:18.040 --> 00:18:21.080
Here we have a bubble
00:18:21.790 --> 00:18:26.059
for each age band and class or crew group.
00:18:26.060 --> 00:18:28.379
Colour shows survival rate,
00:18:28.380 --> 00:18:30.533
while bubble area shows how
00:18:30.534 --> 00:18:32.839
many people are in that group.
00:18:32.840 --> 00:18:34.615
So a tiny bright bubble means
00:18:34.616 --> 00:18:36.450
a high rate among a few people.
00:18:36.520 --> 00:18:39.128
This view uses the 2,205
00:18:39.129 --> 00:18:42.049
people whose ages are known.
00:18:42.050 --> 00:18:45.445
For the last plot we will turn those same
00:18:45.446 --> 00:18:48.759
age groups into a three-dimensional view.
00:18:48.760 --> 00:18:51.161
For this last plot, let's look
00:18:51.162 --> 00:18:53.950
at the same age groups as a skyline.
00:18:54.680 --> 00:18:55.643
The columns make
00:18:55.644 --> 00:18:57.399
the population sizes stand out.
00:18:57.400 --> 00:18:59.813
Height shows people aboard
00:18:59.814 --> 00:19:03.119
and colour still shows survival rate.
00:19:03.120 --> 00:19:05.115
The large groups of young adults
00:19:05.116 --> 00:19:06.869
now look like tall buildings.
00:19:06.870 --> 00:19:09.557
It's the same data we just saw as bubbles,
00:19:09.558 --> 00:19:12.119
but with a different way of drawing them.
00:19:12.120 --> 00:19:13.922
We can still trace it back
00:19:13.923 --> 00:19:16.259
which is our SHAPE provenance idea.
00:19:16.260 --> 00:19:17.511
That's a good place
00:19:17.512 --> 00:19:18.949
to finish the examples,
00:19:18.950 --> 00:19:21.787
and I'll leave you with the sources
00:19:21.788 --> 00:19:24.309
and somewhere to keep exploring.
00:19:24.310 --> 00:19:27.422
But before we finish, let me point you to
00:19:27.423 --> 00:19:30.459
the sources and the rest of the material.
00:19:30.460 --> 00:19:32.690
The DOI links here take you
00:19:32.691 --> 00:19:35.159
to the dataset, ROOT and SHAPE,
00:19:35.160 --> 00:19:37.115
so you can follow up on the data
00:19:37.116 --> 00:19:39.069
and the ideas behind the session.
00:19:39.070 --> 00:19:41.254
If you'd like a deeper dive into
00:19:41.255 --> 00:19:43.239
the open educational resource,
00:19:43.240 --> 00:19:45.779
visit https://gnuplot.emaix.org.
00:19:45.780 --> 00:19:48.579
The QR code takes you there too.
00:19:48.580 --> 00:19:50.519
You will find the lessons,
00:19:50.520 --> 00:19:52.648
code and datasets, ready for you
00:19:52.649 --> 00:19:54.389
to try things out yourself.
00:19:54.390 --> 00:19:58.020
Happy plotting!
|