File: example.ms

package info (click to toggle)
grap 1.49-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 904 kB
  • sloc: cpp: 3,260; yacc: 1,115; lex: 1,056; sh: 941; makefile: 42
file content (3033 lines) | stat: -rw-r--r-- 62,395 bytes parent folder | download
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
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
.\" This file is (c) 1998-2001 Ted Faber (faber@lunabase.org) see COPYRIGHT
.\" for the full copyright and limitations of liabilities.
.EQ
delim $$
.EN
.PP
This is a collection of example graphs that are mostly taken from
Bentley and Kernighan's paper on
.I grap
that is referenced from the manual page.  Please check that for an
explanation of the graphs' meaning.  I use them primarily as a
regression test suite.
.PP
Each graph is accompanied by a brief description and the 
.I grap
code that produced it.
.KS
.PP
A simple copy.  The data is the winning time for the mens' 400m run
taken from the Pittsburgh Press's 
.I
1994 World Almanac and Book of Facts.
.R
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&copy "400mtimes.d"
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
copy "400mtimes.d"
.G2
.KE
.KS
.PP
A simple copy with both $x$ and $y$ coordinates.  The data is from the
same source, but includes the year.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&copy "400mpairs.d"
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
copy "400mpairs.d"
.G2
Simple connection of points.  Same data.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&draw solid
\&copy "400mpairs.d"
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
draw solid
copy "400mpairs.d"
.G2
.KE
.KS
.PP
Spruced up a bit.  We add axis labels and remove some frame
boundaries.  Note that my version of 
.I grap
positions left and right axis labels parallel to the axis.  That
feature can be disabled by specifying
.CW unaligned
as a justification for the label.  The same data is used.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis ht 2 wid 3 left solid bot solid
\&label left "Time (in seconds)" left .25
\&label bot "Olympic 400 Meter Run: Winning Times"
\&draw solid
\&copy "400mpairs.d"
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis ht 2 wid 3 left solid bot solid
label left "Time (in seconds)" left .25
label bot "Olympic 400 Meter Run: Winning Times"
draw solid
copy "400mpairs.d"
.G2
.KE
.KS
.PP
User specified axes, and a font change in the graph.  
You must restore the
font after the terminating 
.CW .G2 .
Commands to 
.I groff
or 
.I pic
are issued at the same place relative to other 
.I grap
commands in the file (as of version 1.50).  The frame is drawn before
the first plotted element (invisible lines count) or when the frame
statement is executed.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&.ft H
\&frame invis ht 2 wid 3 left solid bot solid
\&label left "Time (in seconds)" left .25
\&label bot "Olympic 400 Meter Run: Winning Times"
\&coord x 1894, 1994 y 42, 56
\&draw solid
\&copy "400mpairs.d"
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
.ft H
frame invis ht 2 wid 3 left solid bot solid
label left "Time (in seconds)" left .25
label bot "Olympic 400 Meter Run: Winning Times"
coord x 1894, 1994 y 42, 56
draw solid
copy "400mpairs.d"
.G2
.KE
.KS
.PP
User specified tick placement, and a return to the Roman font.  Same data.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis ht 2 wid 3 left solid bot solid
\&label left "Time (in seconds)" left .25
\&label bot "Olympic 400 Meter Run: Winning Times"
\&coord x 1894, 1994 y 42, 56
\&ticks left out at 44 "44", 46, 48 "48", 50, 52 "52", 54
\&ticks bot in from 1900 to 1980 by 20
\&draw solid
\&copy "400mpairs.d"
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis ht 2 wid 3 left solid bot solid
label left "Time (in seconds)" left .25
label bot "Olympic 400 Meter Run: Winning Times"
coord x 1894, 1994 y 42, 56
ticks left out at 44 "44", 46, 48 "48", 50, 52 "52", 54
ticks bot in from 1900 to 1980 by 20
draw solid
copy "400mpairs.d"
.G2
.KE
.KS
.PP
This graph adds the women's times (from the same source) and includes
different plotting styles and labels.  My version of this graph also
uses the 
.CW until
keyword to include the data rather than external
files.  
.CW until
appears before and after the macro definition.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis ht 2 wid 3 left solid bot solid
\&label left "Time (in seconds)"
\&label bot "Olympic 400 Meter Run: Winning Times"
\&coord x 1894, 1994 y 42, 56
\&ticks left out at 44 , 46 "", 48, 50 "", 52, 54 ""
\&ticks bot in from 1900 to 1980 by 20
\&draw solid
\&copy until "END" thru {next at $1, $2;}
\&1896 54.2
\&1900 49.4
\&[...]
\&1992 43.50
\&END
\&new dotted
\&copy until "END" 
\&1964 52.
\&1968 52.
\&[...]
\&1992 48.83
\&END
\&"Women"  size -3 at 1958,52
\&"Men" size -3 at 1910,47
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis ht 2 wid 3 left solid bot solid
label left "Time (in seconds)"
label bot "Olympic 400 Meter Run: Winning Times"
coord x 1894, 1994 y 42, 56
ticks left out at 44 , 46 "", 48, 50 "", 52, 54 ""
ticks bot in from 1900 to 1980 by 20
draw solid
copy until "END" thru {next at $1, $2;}
1896 54.2
1900 49.4
1904 49.2
1908 50
1912 48.2
1920 49.6
1924 47.6
1928 47.8
1932 46.2
1936 46.5
1948 46.2
1952 45.9
1956 46.7
1960 44.9
1964 45.1
1968 43.8
1972 44.66
1976 44.26
1980 44.60
1984 44.27
1988 43.87
1992 43.50
END
new dotted
copy until "END" 
1964 52.
1968 52.
1972 51.08
1976 49.29
1980 48.88
1984 48.83
1988 48.95
1992 48.83
END
"Women"  size -3 at 1958,52
"Men" size -3 at 1910,47
.G2
.KE
.KS
.PP
Another simple copy.  Bentley and Kernighan use phone installations, I
use numbers of hosts on the Internet.  The data is from 
.CW ftp://nic.merit.edu/nsfnet/statistics/history.hosts ,
maintained by:
.DS 
Merit Network
4251 Plymouth Road
Suite C
Ann Arbor, MI 48105-2785
734-764-9430
.DE
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&copy "internet.d"
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
copy "internet.d"
.G2
.KE
.KS
.PP
The same data plotted on a logarithmic $y$ scale, and rescaled to
megahosts, which is less humorous than megaphones.  The placement of
the bottom ticks shows the 
.CW
from .. to .. by
.R
construct.  The filename is given after the macro for variety (and to
test that feature).
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&coord x 80,100 y 1e-4, 30 log y
\&ticks bot at 80 "1980", 100 "2000"
\&ticks bot from 85 to 95 by 5 "' %g"
\&ticks left 
\&label left "Millions of Hosts" left .25
\&label bot "Year"
\&draw solid
\&copy thru { next at $1, $2/1e6;} "internet.d" 
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
coord x 80,100 y 1e-4, 30 log y
ticks bot at 80 "1980", 100 "2000"
ticks bot from 85 to 95 by 5 "' %g"
ticks left 
label left "Millions of Hosts" left .25
label bot "Year"
draw solid
copy thru { next at $1, $2/1e6;} "internet.d"
.G2
.KE
.KS
.PP
A demo of 
.I grap 's
annotation abilities, mostly.  The data is all in the graph specification.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame ht 2 wid 2
\&coord x 0,100 y 0,100
\&grid bot dotted from 20 to 80 by 20
\&grid left dotted from 20 to 80 by 20
\&
\&"Text above" above at 50,50
\&"Text rjust   " rjust at 50,50
\&bullet at 80,90
\&vtick at 80,80
\&box at 80,70
\&times at 80,60
\&
\&circle at 50,50
\&circle at 50,80 radius .25
\&line dashed from 10,90 to 30,90
\&arrow from 10,70 to 30,90
\&
\&draw A solid
\&draw B dashed delta
\&next A at 10,10
\&next B at 10,20
\&next A at 50,20
\&next A at 90,10
\&next B at 50,30
\&next B at 90,30
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame ht 2 wid 2
coord x 0,100 y 0,100
grid bot dotted from 20 to 80 by 20
grid left dotted from 20 to 80 by 20

"Text above" above at 50,50
"Text rjust   " rjust at 50,50
bullet at 80,90
vtick at 80,80
box at 80,70
times at 80,60

circle at 50,50
circle at 50,80 radius .25
line dashed from 10,90 to 30,90
arrow from 10,70 to 30,90

draw A solid
draw B dashed delta
next A at 10,10
next B at 10,20
next A at 50,20
next A at 90,10
next B at 50,30
next B at 90,30
.G2
.KE
.KS
.PP
A simple macro demo.  Again, no data.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame ht 1.5 wid 1.5
\&define square {($1) * ($1)}
\&define root {($1)^.5 }
\&define P {
\&	times at i, square(i); i = i +1;
\&	circle at j, root(j); j= j+5;
\&}
\&i = 1; j = 5
\&P; P; P; P; P
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame ht 1.5 wid 1.5
define square {($1) * ($1)}
define root {($1)^.5 }
define P {
	times at i, square(i); i = i +1;
	circle at j, root(j); j= j+5;
}
i = 1; j = 5
P; P; P; P; P
.G2
.KE
.KS
.PP
The number of Representatives to the U.S. Congress versus population
of the states.  My data is more recent than that of Bentley/Kernighan,
so the graph is different from theirs.  Data is from the U.S. Census
Bureau at 
.CW http://www.census.gov/ , 
specifically
.CW http://www.census.gov/population/www/censusdata/apportionment.html .
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&label left "Representatives to Congress"
\&label bot "Population (Millions)"
\&coord x .3, 35 y .8, 60 log log
\&define PlotState { circle at $3/1e6, $2; }
\&copy "states.d" thru PlotState
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
label left "Representatives to Congress"
label bot "Population (Millions)"
coord x .3, 35 y .8, 60 log log
define PlotState { circle at $3/1e6, $2; }
copy "states.d" thru PlotState
.G2
.KE
.KS
.PP
A 2-axis plot.  We redefine square because the macro example graph
changed it.  I advise against changing the predefined macro
definitions because macros persist across graphs.  The same data is
plotted.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&define square {"\\s-2\\(sq\\s0"}
\&frame ht 3 wid 3.5
\&label left "Population in Millions (Plotted as \\(bu)"
\&label bot "Rank in Population"
\&label right "Representatives (Plotted as \\(sq)"
\&coord pop x 0,51 y .2,35 log y
\&coord rep x 0,51 y .3,100 log y
\&ticks left out at pop .3,1,3,10,30
\&ticks bot out at pop 1,50
\&ticks right out at rep 1,3,10,30,100
\&thisrank = 50
\&copy "states.d" thru {
\&	bullet at pop thisrank,$3/1e6
\&	square at rep thisrank,$2
\&	thisrank = thisrank -1
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
define square {"\s-2\(sq\s0"}
frame ht 3 wid 3.5
label left "Population in Millions (Plotted as \(bu)"
label bot "Rank in Population"
label right "Representatives (Plotted as \(sq)"
coord pop x 0,51 y .2,35 log y
coord rep x 0,51 y .3,100 log y
ticks left out at pop .3,1,3,10,30
ticks bot out at pop 1,50
ticks right out at rep 1,3,10,30,100
thisrank = 50
copy "states.d" thru {
	bullet at pop thisrank,$3/1e6
	square at rep thisrank,$2
	thisrank = thisrank -1
}
.G2
.KE
.KS
.PP
A sine wave plotted by a 
.CW for
loop with \(*p calculated with the internal
.CW atan2()
function.  No data.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame ht 1 wid 3
\&draw solid
\&pi = atan2(0,-1)
\&for i from 0 to 2* pi by .1 do { next at i, sin(i); }
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame ht 1 wid 3
draw solid
pi = atan2(0,-1)
for i from 0 to 2* pi by .1 do { next at i, sin(i); }
.G2
.KE
.KS
.PP
Bentley and Kernighan do this graph with Kentucky Derby winning times.
I don't have them, so I used the 400m times again.  My program is
slightly different because the 400m run times have gaps.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&label left "Winning Time" left .3
\&label bot "Olympics Men's 400 m"
\&bestsofar = 1000
\&anchor = 0
\&copy "400mpairs.d" thru {
\&	bullet at $1,$2
\&	if ( anchor != 0 ) then { 
\&		line from anchor, bestsofar to $1,bestsofar
\&	}
\&	bestsofar = min(bestsofar,$2)
\&	if ( bestsofar == $2 ) then { 
\&		anchor = $1
\&	}
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
label left "Winning Time" left .3
label bot "Olympics Men's 400 m"
bestsofar = 1000
anchor = 0
copy "400mpairs.d" thru {
	bullet at $1,$2
	if ( anchor != 0 ) then { 
		line from anchor, bestsofar to $1,bestsofar
	}
	bestsofar = min(bestsofar,$2)
	if ( bestsofar == $2 ) then { 
		anchor = $1
	}
}
.G2
.KE
.KS
.PP
Bentley and Kernighan discuss the regression and modeling that these
graphs reflect.  The data is the U.S. population from the U.S. Census
bureau.  This shows off the ability to place two plots relative to
each other using the 
.CW graph
statement.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&graph Linear
\&coord x 1785, 1955 y 0, 160
\&label left "Population in Millions" left .3
\&label right "Linear Scale" unaligned "Linear Fit" right .4
\&ticks bot off
\&copy "usapop.d"
\&define fit { 35 + 1.4 * ($1-1870) }
\&line from 1850, fit(1850) to 1950,fit(1950)
\&graph Exponential with .Frame.n at Linear.Frame.s - (0, .05)
\&coord x 1785, 1955 y 3, 160 log y
\&label left "Population in Millions" left .3
\&label right "Logarithmic Scale" unaligned "Exponential Fit" right .4
\&copy "usapop.d"
\&define fit { exp(.75 + .012 * ($1-1800)) }
\&line from 1790, fit(1790) to 1920,fit(1920)
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
graph Linear
coord x 1785, 1955 y 0, 160
label left "Population in Millions" left .3
label right "Linear Scale" unaligned "Linear Fit" right .4
ticks bot off
copy "usapop.d"
define fit { 35 + 1.4 * ($1-1870) }
line from 1850, fit(1850) to 1950,fit(1950)
graph Exponential with .Frame.n at Linear.Frame.s - (0, .05)
coord x 1785, 1955 y 3, 160 log y
label left "Population in Millions" left .3
label right "Logarithmic Scale" unaligned "Exponential Fit" right .4
copy "usapop.d"
define fit { exp(.75 + .012 * ($1-1800)) }
line from 1790, fit(1790) to 1920,fit(1920)
.G2
.KE
.KS
.PP
Another re-expression of the U.S. population data.  Uses plenty of
.I grap 
arithmetic and an 
.I eqn
axis label (which is 
.CW unaligned ).
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&label left "Population in Millions" left .3
\&label right "$x$ re-expressed as" unaligned "" "$space 0 left  
\&	( { date -1600 } over 100 right ) sup 7$" right .4
\&define newx { exp(7*(log(($1-1600)/100))) }
\&ticks bot out at newx(1800) "1800", newx(1850) "1850", \\
\&	newx(1900) "1900"
\&copy "usapop.d" thru {
\&	if $1 <= 1900 then { bullet at newx($1),$2 }
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
label left "Population in Millions" left .3
label right "$x$ re-expressed as" unaligned "" "$space 0 left ( { date -1600 } over 100 right ) sup 7$" right .4
define newx { exp(7*(log(($1-1600)/100))) }
ticks bot out at newx(1800) "1800", newx(1850) "1850", \
	newx(1900) "1900"
copy "usapop.d" thru {
	if $1 <= 1900 then { bullet at newx($1),$2 }
}
.G2
.KE
.KS
.PP
A simple copy of a multiple field data file.  The data is the 5th,
50th, and 95th percentiles for the heights of boys in America at
different ages.  The data is reported from Thomas J. Glover's
remarkable
.I Pocket 
.I Ref ,
which reports data from the National Center for Health Statistics.  
.I
Pocket Ref
.R
is published by Sequoia Publishing, Littleton, CO.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&copy "boyhts.d"
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
copy "boyhts.d"
.G2
.KE
.KS
.PP
The same data with a linear regression, and the 90% confidence
intervals drawn as lines.  Note the cascading assignment
statements (patch courtesy of Bruce Lilly).  (Bentley and
Kernighan's data is in centimeters, mine is in inches, so a different
conversion to feet is used.)
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&label left "Heights in Feet"
\&label bot "Heights of Boys in the US Ages 2-18"
\&cmpft = 12
\&minx = 1e12; maxx = -1e12
\&n = sigx = sigx2 = sigy = sigxy = 0;
\&copy "boyhts.d" thru {
\&	line from $1, $2/cmpft to $1, $4/cmpft
\&	ty = $3 / cmpft
\&	bullet at $1, ty
\&	n = n+1
\&	sigx = sigx + $1; sigx2 = sigx2 + $1 * $1
\&	sigy = sigy + ty; sigxy = sigxy + $1*ty
\&	minx = min(minx,$1); maxx = max(maxx,$1);
\&}
\&slope = ( n*sigxy - sigx* sigy) / (n*sigx2 - sigx * sigx)
\&inter = ( sigy - slope * sigx) / n
\&line from minx, slope * minx+inter to maxx, slope * maxx + inter
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
label left "Heights in Feet"
label bot "Heights of Boys in the US Ages 2-18"
cmpft = 12
minx = 1e12; maxx = -1e12
n = sigx = sigx2 = sigy = sigxy = 0;
copy "boyhts.d" thru {
	line from $1, $2/cmpft to $1, $4/cmpft
	ty = $3 / cmpft
	bullet at $1, ty
	n = n+1
	sigx = sigx + $1; sigx2 = sigx2 + $1 * $1
	sigy = sigy + ty; sigxy = sigxy + $1*ty
	minx = min(minx,$1); maxx = max(maxx,$1);
}
slope = ( n*sigxy - sigx* sigy) / (n*sigx2 - sigx * sigx)
inter = ( sigy - slope * sigx) / n
line from minx, slope * minx+inter to maxx, slope * maxx + inter
.G2
.KE
.KS
.PP
This is a 4 linestyle plot with a copy statement that adds labels.
The scales are user-defined, and the $y$ axis is logarithmic.  The
data is the number of male and female officers and enlisted personnel
in the U.S. Armed forces from 1940-1993 from the Pittsburgh Press 
.I 
World Almanac and Book of Facts.
.R
This graph has more data than the equivalent from Bentley and Kernighan.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&coord x 38, 95 y .8, 10000 log y
\&label bot "U.S. Military Personnel"
\&label left "Thousands" left .25
\&draw of solid
\&draw ef dashed
\&draw om dotted
\&draw em solid
\&copy "army.d" thru {
\&	next of at $1, $3
\&	next ef at $1, $5
\&	next om at $1, $2
\&	next em at $1, $4
\&}
\&copy until "XXX" thru { "$1 $2" size -3 at 60, $3; }
\&Enlisted Men 1200
\&Male Officers 140
\&Enlisted Women 12
\&Female Officers 2.5
\&XXX
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
coord x 38, 95 y .8, 10000 log y
label bot "U.S. Military Personnel" 
label left "Thousands" left .25
draw of solid
draw ef dashed
draw om dotted
draw em solid
copy "army.d" thru {
	next of at $1, $3
	next ef at $1, $5
	next om at $1, $2
	next em at $1, $4
}
copy until "XXX" thru { "$1 $2" size -3 at 60, $3; }
Enlisted Men 1200
Male Officers 140
Enlisted Women 12
Female Officers 2.5
XXX
.G2
.KE
.KS
.PP
Obfuscation of data via scatter plots.  Three aligned graphs are
produced that plot the numbers of enlisted men as functions of male
officers, female officers, and enlisted women.  The plotting symbol is
the year in question.  Same data as above.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&graph A 
\&frame ht 1.6667 wid 1.6667
\&label bot "Male_Officers"
\&label left "Enlisted_Men"
\&coord log log
\&ticks off
\&copy "army.d" thru { "\s-3$1\s+3" at $2,$4; }
\&graph A with .Frame.w at A.Frame.e +(.1,0)
\&frame ht 1.6667 wid 1.6667
\&label bot "Female_Officers"
\&coord log log
\&ticks off
\&copy "army.d" thru { "\s-3$1\s+3" at $3,$4; }
\&graph A with .Frame.w at A.Frame.e +(.1,0)
\&frame ht 1.6667 wid 1.6667
\&label bot "Enlisted_Women"
\&coord log log
\&ticks off
\&copy "army.d" thru { "\s-3$1\s+3" at $5,$4; }
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
graph A 
frame ht 1.6667 wid 1.6667
label bot "Male_Officers"
label left "Enlisted_Men"
coord log log
ticks off
copy "army.d" thru { "\s-3$1\s+3" at $2,$4; }
graph A with .Frame.w at A.Frame.e +(.1,0)
frame ht 1.6667 wid 1.6667
label bot "Female_Officers"
coord log log
ticks off
copy "army.d" thru { "\s-3$1\s+3" at $3,$4; }
graph A with .Frame.w at A.Frame.e +(.1,0)
frame ht 1.6667 wid 1.6667
label bot "Enlisted_Women"
coord log log
ticks off
copy "army.d" thru { "\s-3$1\s+3" at $5,$4; }
.G2
.KE
.KS
.PP
One of my favorites.  The solution of a differential equation and the
slope field it passes through.  It shows off nested 
.CW for
loops (one using = as a synonym for from) and 
.I eqn
labels.  The data is in the graph description.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame ht 2.5 wid 2.5
\&coord x 0,1 y 0,1
\&label bot "Direction Field is $y prime = x sup 2 / y$"
\&label left "$y = sqrt { ( 2 x sup 3 + 1 ) / 3 }$"
\&ticks left in 0 left .1 at 0,1
\&ticks bot in 0 down .1 at 0,1
\&len = .04
\&for tx from .01 to .91 by .1 do {
\&	for ty from .01 to .91 by .1 do {
\&		deriv = tx*tx/ty
\&		scale = len / sqrt(1 + deriv*deriv)
\&		line from tx,ty to tx+scale, ty+scale*deriv
\&	}
\&}
\&draw solid
\&for tx = 0 to 1 by .05 do {
\&	next at tx, sqrt((2*tx*tx*tx+1)/3)
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame ht 2.5 wid 2.5
coord x 0,1 y 0,1
label bot "Direction Field is $y prime = x sup 2 / y$"
label left "$y = sqrt { ( 2 x sup 3 + 1 ) / 3 }$"
ticks left in 0 left .1 at 0,1
ticks bot in 0 down .1 at 0,1
len = .04
for tx from .01 to .91 by .1 do {
	for ty from .01 to .91 by .1 do {
		deriv = tx*tx/ty
		scale = len / sqrt(1 + deriv*deriv)
		line from tx,ty to tx+scale, ty+scale*deriv
	}
}
draw solid
for tx = 0 to 1 by .05 do {
	next at tx, sqrt((2*tx*tx*tx+1)/3)
}
.G2
.KE
.KS
.PP
More population studies.  State population rank vs. population, with
the population on a log scale.  A regression line is also plotted.  I
used the same line as Bentley and Kernighan, although my data is more
recent.  The top labels are generated by a series of macros, the frame
size is enlarged, and the plotting symbol is the state abbreviation.
This graph uses the same census data as above.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame wid 5 ht 4
\&label left "Rank in Population"
\&label bot "Population (in Millions)"
\&label top "$log sub 2$ Population"
\&coord x .3, 35 y 0, 51 log x
\&define L { (2.0^$1)/1e6 "$1" }
\&ticks bot out at .5, 1, 2, 5, 10, 20
\&ticks left out from 10 to 50 by 10
\&ticks top out at L(19), L(20), L(21), L(22), L(23), L(24), L(25)
\&thisy = 50
\&copy "states.d" thru {
\&	"$1" size -4 at $3/1e6, thisy
\&	thisy = thisy-1
\&}
\&line dotted from 15.3,1 to .515, 50
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame wid 5 ht 4
label left "Rank in Population"
label bot "Population (in Millions)"
label top "$log sub 2$ Population"
coord x .3, 35 y 0, 51 log x
define L { (2.0^$1)/1e6 "$1" }
ticks bot out at .5, 1, 2, 5, 10, 20
ticks left out from 10 to 50 by 10
ticks top out at L(19), L(20), L(21), L(22), L(23), L(24), L(25)
thisy = 50
copy "states.d" thru {
	"$1" size -4 at $3/1e6, thisy
	thisy = thisy-1
}
line dotted from 15.3,1 to .515, 50
.G2
.KE
.KS
.PP
A nearly useless plot of the populations of different states.  Same data.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis ht .3 wid 5 bottom solid
\&label bot "Populations (in Millions) of the 50 States"
\&coord x .3, 35 y 0, 1 log x
\&ticks bot out at .5, 1, 2, 5, 10, 20
\&ticks left off
\&copy "states.d" thru { vtick at $3/1e6, .5; }
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis ht .3 wid 5 bottom solid
label bot "Populations (in Millions) of the 50 States"
coord x .3, 35 y 0, 1 log x
ticks bot out at .5, 1, 2, 5, 10, 20
ticks left off
copy "states.d" thru { vtick at $3/1e6, .5; }
.G2
.KE
.KS
.PP
A slight improvement, as the states are spread out and plotted with
their symbols.  The 
.CW rand() 
function is used to position them vertically, which shows off the
function, but doesn't guarantee a legible graph.  Same data.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis ht 1 wid 5 bottom solid
\&label bot "Populations (in Millions) of the 50 States"
\&coord x .3, 35 y 0, 1000 log x
\&ticks bot out at .5, 1, 2, 5, 10, 20
\&ticks left off
\&copy "states.d" thru { "$1" size -4 at $3/1e6, 100+900*rand(); }
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis ht 1 wid 5 bottom solid
label bot "Populations (in Millions) of the 50 States"
coord x .3, 35 y 0, 1000 log x
ticks bot out at .5, 1, 2, 5, 10, 20
ticks left off
copy "states.d" thru { "$1" size -4 at $3/1e6, 100+900*rand(); }
.G2
.KE
.KS
.PP
A histogram of the same data.  The input file is a result of running
the census data through the 
.I awk
script that Bentley and Kernighan describe.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis bot solid
\&label bot "Populations (in Millions) of the 50 States"
\&label left "Number of States" left .1
\&ticks bot out from 0 to 35 by 5
\&coord x 0, 35 y 0, 13
\&copy "states2.d" thru {
\&	line from $1,0 to $1,$2
\&	line from $1, $2 to $1+1, $2
\&	line from $1+1,$2 to $1+1,0
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis bot solid
label bot "Populations (in Millions) of the 50 States"
label left "Number of States" left .1
ticks bot out from 0 to 35 by 5
coord x 0, 35 y 0, 13
copy "states2.d" thru {
	line from $1,0 to $1,$2
	line from $1, $2 to $1+1, $2
	line from $1+1,$2 to $1+1,0
}
.G2
.KE
.KS
.PP
A \*Qlolliplot \*U histogram of the same data.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis bot solid
\&label bot "Populations (in Millions) of the 50 States"
\&label left "Number of States" left .1
\&ticks bot out from 0 to 35 by 5
\&coord x 0, 35 y 0, 13
\&copy "states2.d" thru {
\&	line dotted from $1+.5,0 to $1+.5,$2
\&	"\(bu" size +3 at $1+.5, $2
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis bot solid
label bot "Populations (in Millions) of the 50 States"
label left "Number of States" left .1
ticks bot out from 0 to 35 by 5
coord x 0, 35 y 0, 13
copy "states2.d" thru {
	line dotted from $1+.5,0 to $1+.5,$2
	"\(bu" size +3 at $1+.5, $2
}
.G2
.KE
.KS
.PP
A histogram of state abbreviations.  The data has been massaged by the
.I awk
program described by Bentley and Kernighan.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis wid 4 ht 2.5 bot solid
\&label bot "Populations (in Millions) of the 50 States"
\&ticks bot out from 0 to 35 by 5
\&ticks left off
\&coord x 0, 35 y 0, 13
\&copy "states3.d" thru {"$1" size -4 at $2+.5, $3+.5; }
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis wid 4 ht 2.5 bot solid
label bot "Populations (in Millions) of the 50 States"
ticks bot out from 0 to 35 by 5
ticks left off
coord x 0, 35 y 0, 13
copy "states3.d" thru {"$1" size -4 at $2+.5, $3+.5; }
.G2
.KE
.KS
.PP
A bar graph of profiler output.  The output is from running 
.I grap
on this file.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&ticks left off
\&cury = 0
\&barht = .7
\&copy "prof2.d" thru {
\&	line from 0,cury to $1, cury
\&	line from $1, cury to $1, cury-barht
\&	line from 0, cury-barht to $1, cury-barht
\&	"  $2" ljust at 0, cury-barht/2
\&	cury = cury-1
\&}
\&line from 0,0 to 0,cury+1-barht
\&bars = -cury
\&frame invis ht bars/3 wid 3
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
ticks left off
cury = 0
barht = .7
copy "prof2.d" thru {
	line from 0,cury to $1, cury
	line from $1, cury to $1, cury-barht
	line from 0, cury-barht to $1, cury-barht
	"  $2" ljust at 0, cury-barht/2
	cury = cury-1
}
line from 0,0 to 0,cury+1-barht
bars = -cury
frame invis ht bars/3 wid 3
.G2
.KE
.KS
.PP
The creative graph of state heights and volcano heights from their
grap paper.  The data was included in the graph description, which
(according to Bruce Lilly) is from John W. Tukey's classic 1977 text 
.I
Exploratory
Data Analysis,
.R
Chapter 10.  Tukey cites \*QThe World Almanac, 1966, page 269.  Their
source: National Geographic Society.\*U  The format of the graph is
also similar to a graph on pg. 40 (exhibit 5, chapter 2).  All those
attributions are from Bruce Lilly.  I don't have the relevant material
to verify it, but have no reason to doubt the accuracy of the information.
.EQ
delim off
.EN
.DS
.ft CW
.ps 8
.vs 10
\&.G1
\&frame invis ht 4 wid 3 bot solid
\&ticks off
\&coord x .5, 3.5 y 0,25
\&define Ht { "- $1,000 -" size -3 at 2, $1 }
\&Ht(5); Ht(10); Ht(15); Ht(20);
\&"Highest Point" "in 50 States" at 1,23
\&"Heights of" "219 Volcanos" at 3,23
\&"Feet" at 2,21.5; arrow from 2,22.5 to 2,24
\&define box {
\&	xc = $1; xl = xc - boxwidth/2; xh = xc+boxwidth/2
\&	y1 = $2; y2 = $3; y3 = $4; y4= $5; y5 = $6
\&	bullet at xc,y1
\&	"  $7" size -3 ljust at xc, y1
\&	line from (xc,y1) to (xc,y2)
\&	line from (xl,y2) to (xh,y2)
\&	line from (xl,y3) to (xh,y3)
\&	line from (xl,y4) to (xh,y4)
\&	line from (xl,y2) to (xl,y4)
\&	line from (xh,y2) to (xh,y4)
\&	line from (xc,y4) to (xc,y5)
\&	bullet at xc,y5
\&	"  $8" ljust size -3  at (xc,y5)
\&}
\&boxwidth = .3
\&box(1, .3, 2.0, 4.6, 11.2,20.3, Florida, Alaska)
\&box(3,.2, 3.7, 6.5, 9.5, 19.9, Ilhanova, Guallatiri)
\&.G2
.ft
.DE
.KE
.KS
.EQ
delim $$
.EN
.G1
frame invis ht 4 wid 3 bot solid
ticks off
coord x .5, 3.5 y 0,25
define Ht { "- $1,000 -" size -3 at 2, $1 }
Ht(5); Ht(10); Ht(15); Ht(20);
"Highest Point" "in 50 States" at 1,23
"Heights of" "219 Volcanos" at 3,23
"Feet" at 2,21.5; arrow from 2,22.5 to 2,24
define box {
	xc = $1; xl = xc - boxwidth/2; xh = xc+boxwidth/2
	y1 = $2; y2 = $3; y3 = $4; y4= $5; y5 = $6
	bullet at xc,y1
	"  $7" size -3 ljust at xc, y1
	line from (xc,y1) to (xc,y2)
	line from (xl,y2) to (xh,y2)
	line from (xl,y3) to (xh,y3)
	line from (xl,y4) to (xh,y4)
	line from (xl,y2) to (xl,y4)
	line from (xh,y2) to (xh,y4)
	line from (xc,y4) to (xc,y5)
	bullet at xc,y5
	"  $8" ljust size -3  at (xc,y5)
}
boxwidth = .3
box(1, .3, 2.0, 4.6, 11.2,20.3, Florida, Alaska)
box(3,.2, 3.7, 6.5, 9.5, 19.9, Ilhanova, Guallatiri)
.G2
.KE
.KS
.PP
A large but boring graph.  No data, but it does show off passing size
parameters to 
.I pic ,
and using non-brace macro delimiters.
.EQ
delim off
.EN
.DS
.ft CW
\&.ps 14
\&.vs 18
\&.G1 4
\&frame ht 2 wid 2
\&label left "Response Variable" left .2
\&label bot "Factor Variable" down .1
\&line from 0,0 to 1,1
\&line dotted from .5,0 to .5,1
\&define blob X "\\v'.1m'\\(bu\\v'-.1m'" X
\&blob at 0,.5; blob at .5, .5; blob at 1,.5
\&.G2
\&.ps 10
\&.vs 12
.ft
.DE
.EQ
delim $$
.EN
.ps 14
.vs 18
.G1 4
frame ht 2 wid 2
label left "Response Variable" left .2
label bot "Factor Variable" down .1
line from 0,0 to 1,1
line dotted from .5,0 to .5,1
define blob X "\v'.1m'\(bu\v'-.1m'" X
blob at 0,.5; blob at .5, .5; blob at 1,.5
.G2
.ps 10
.vs 12
.KE
.KS
.PP
This displays all the macros defined in 
.CW grap.defines .
No data.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&define box {"\\s-2\\f(ZD\\N'110'\\fP\\s0"}
\&frame ht 2 wid 2
\&coord x 0,3 y 0,6
\&ticks off
\&ticks left in left .1 from 1 to 5
\&ticks right in from 1 to 5 ""
\&ticks bot in down .1 from 1 to 2
\&ticks top in from 1 to 2 ""
\&bullet at 1,1
\&plus at 1,2
\&box at 1,3
\&star at 1,4
\&dot at 1,5
\&times at 2,1
\&htick at 2,2
\&vtick at 2,3
\&square at 2,4
\&delta at 2,5
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
define box {"\s-2\f(ZD\N'110'\fP\s0"}
frame ht 2 wid 2
coord x 0,3 y 0,6
ticks off
ticks left in left .1 from 1 to 5
ticks right in from 1 to 5 ""
ticks bot in down .1 from 1 to 2
ticks top in from 1 to 2 ""
bullet at 1,1
plus at 1,2
box at 1,3
star at 1,4
dot at 1,5
times at 2,1
htick at 2,2
vtick at 2,3
square at 2,4
delta at 2,5
.G2
.KE
.KS
.PP
We saw this graph earlier using line drawing commands.  This version
uses the 
.CW bar
extension.  Bars are centered, so the 0.5 unit fudge factor is used.
If I were graphing this from scratch, I would rewrite the 
.I awk
script to place the bars correctly.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis bot solid
\&label bot "Populations (in Millions) of the 50 States"
\&label left "Number of States" left .1
\&ticks bot out from 0 to 35 by 5
\&coord x 0, 35 y 0, 13
\&copy "states2.d" thru {
\&	bar up $1+0.5 ht $2 fill 0.125
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis bot solid
label bot "Populations (in Millions) of the 50 States"
label left "Number of States" left .1
ticks bot out from 0 to 35 by 5
coord x 0, 35 y 0, 13
copy "states2.d" thru {
	bar up $1+0.5 ht $2 fill 0.125
}
.G2
.KE
.KS
.PP
The same graph with bars extending in the x direction.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis bot solid
\&label left "Populations (in Millions) of the 50 States"
\&label bot "Number of States"
\&ticks left out from 0 to 35 by 5
\&coord x 0, 13  y -0, 35 
\&copy "states2.d" thru {
\&	bar right $1+0.5 ht $2 fill 0.125
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis bot solid
label left "Populations (in Millions) of the 50 States"
label bot "Number of States"
ticks left out from 0 to 35 by 5
coord x 0, 13  y 0, 35 
copy "states2.d" thru {
	bar right $1+0.5 ht $2 fill 0.125
}
.G2
.KE
.KS
.PP
Demonstration of negative bar heights.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis bot solid
\&copy until "DONE" thru {
\&	bar up $1 ht $2
\&}
\&1 -2
\&2 -1
\&3 0
\&4 1
\&5 2
\&DONE
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis bot solid
copy until "DONE" thru {
	bar up $1 ht $2
}
1 -2
2 -1
3 0
4 1
5 2
DONE
.G2
.KE
.KS
.PP
A display of two timing measurements and the components thereof.  The
data is fabricated, I just wanted to show the format, including both
formats of 
.CW bar
statement.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis bot solid left solid
\&ticks bottom off
\&grid bottom invis at 1 "OS 1", 2 "OS2"
\&coord y 0, 10
\&copy until "DONE" thru {
\&	bar up $1 ht $2 wid 0.5 base $3 fill $4
\&}
\&1 3 0 0.25
\&1 1 3 0.5
\&1 4 4 0.9
\&2 1 0 0.25
\&2 4 1 0.5
\&2 2 5 0.9
\&DONE
\&copy until "DONE" thru {
\&	bar 1.5,$1, 1.75, $1+0.2 fill $2
\&	$3 size -2 ljust at 1.8,$1+0.1
\&}
\&9 0.25 "Copying"
\&8.5 0.5 "Initialization"
\&8  0.9 "Checksum"
\&DONE
\&bar 1.45,9.35, 2.25, 7.85 dashed
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis bot solid left solid
ticks bottom off
grid bottom invis at 1 "OS 1", 2 "OS2"
coord y 0, 10
copy until "DONE" thru {
	bar up $1 ht $2 wid 0.5 base $3 fill $4
}
1 3 0 0.25
1 1 3 0.5
1 4 4 0.9
2 1 0 0.25
2 4 1 0.5
2 2 5 0.9
DONE
copy until "DONE" thru {
	bar 1.5,$1, 1.75, $1+0.2 fill $2
	$3 size -2 ljust at 1.8,$1+0.1
}
9 0.25 "Copying"
8.5 0.5 "Initialization"
8  0.9 "Checksum"
DONE
bar 1.45,9.35, 2.25, 7.85 dashed
.G2
.KE
.KS
.PP
This shows the new filling and linestyle capabilities of the 
.CW circle
and 
.CW bar
commands
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&bar (1,1), (0,0) fill 0.25
\&circle at 0.5,0.5 rad 0.5 dashed 0.05 fill 0.5
\&.G2
.ft
.DE
.G1
bar (1,1), (0,0) fill 0.25
circle at 0.5,0.5 rad 0.5 dashed 0.05 fill 0.5
.G2
.KE
.KS
This is a more complex example of nested macros from Anindo Banerjea's
thesis.  This originally caught errors in the use of multiple
positioning commands for labels.  I don't know what the data are, but
a full explanation is in his Ph.D thesis.  In-line data 
and the groff for the caption are elided.  Two lines present in the
real graph are missing from this one.
.DS
.ft CW
.ps 8
.vs 10
\&.ds ** \\v'+.2m'\\fB*\\fP\\v'-.2m'
\&.vs 10
\&.G1
\&define myplot % # (symbol)
\&next linename at $1,$2
\&symb at $1,$2
\&%
\&graph A
\&frame invis ht 1.667 wid 2.0 left solid bot solid
\&coord y 0,70
\&label bot "delay (ms)" "\\fIi)\\fP" down 0.3
\&label left "load" unaligned "index" up .9
\&label right "Xmin =  2: \\(bu" unaligned ljust size -3 "Xmin =  4:\\(sq" \\
\&	"Xmin =  8:\\(ci" "Xmin = 16: \\*(**" left 1.4 up 0.5
\&draw a solid
\&define symb % bullet %
\&define linename { a }
\&copy until "XXX" thru myplot 
\&50  42.000
\&...
\&XXX
\&draw b solid
\&define symb % square %
\&define linename { b }
\&copy until "XX1" thru myplot 
\&50  22.000
\&...
\&XX1
\&.G2
.ft
.ps 10
.vs 12
.DE
.ds ** \v'+.2m'\fB*\fP\v'-.2m'
.vs 10
.G1 2i
define myplot % # (symbol)
next linename at $1,$2
symb at $1,$2
%
graph A
frame invis ht 1.667 wid 2.0 left solid bot solid
coord y 0,70
label bot "delay (ms)" "\fIi)\fP" down 0.3
label left "load" unaligned "index" up .9
label right "Xmin =  2: \(bu" unaligned ljust size -3 "Xmin =  4:\(sq" \
	"Xmin =  8:\(ci" "Xmin = 16: \*(**" left 1.4 up 0.5
draw a solid
define symb % bullet %
define linename { a }
copy until "XXX" thru myplot 
50  42.000
60  41.800
70  41.400
80  40.000
90  39.000
100  37.800
110  36.400
120  33.000
130  31.000
140  28.800
150  26.400
160  21.000
170  18.000
180  14.800
190  11.400
200   4.000
210   4.000
220   4.000
XXX
draw b solid
define symb % square %
define linename { b }
copy until "XX1" thru myplot 
50  22.000
60  21.800
70  21.600
80  20.800
90  20.200
100  19.600
110  18.800
120  17.000
130  16.000
140  14.800
150  13.600
160  10.800
170   9.200
180   7.600
190   5.800
200   2.000
210   2.000
220   2.000
XX1
.G2
.LP
\fB Figure 1.\fP Queueing Delay index vs. other load indices: Graph
\fIi)\fP shows that the proposed load index is monotonically decreasing
as a function of delay if all other factors are constant. Graph
\fIii)\fP shows that it is linear in bandwidth and graph \fIiii)\fP
shows that it is linear in the path length of the route provided the
delay requirement per hop remains constant.
.vs 12
.KE
.KS
.PP
This graph is pretty brutal all around.  Nested macros and constructed
filenames produce a bar graph (some of the components separated by
dots in the included filenames were originally pathname components).
This source is also from Anindo Banerjea, and caught bugs related to
.CW if
and 
.CW for 
statements.  Anindo wrote this to display a graph for
his thesis, not to demonstrate perfect
.CW grap 
programming form.  His graphs are used with his permission, I've made
minor tweaks to his code to make them more pretty under this version
of 
.CW grap .
.DS
.ft CW
.ps 8
.vs 10
\&.G1
\&define write_name % #(code,X,Y)
\&  if ($1 == 1) then {
\&    "\\s-2G\\s+2" above at $2,$3 
\&  }
\&  if ($1 == 2) then {
\&    "\\s-2H\\s+2" above at $2,$3
\&  }
\&  if ($1 == 3) then {
\&    "\\s-2L\\s+2" above at $2,$3
\&  }
\&  if ($1 == 4) then {
\&    "\\s-2I\\s+2" above at $2,$3
\&  }
\&  if ($1 == 5) then {
\&    "\\s-2R1\\s+2" above at $2,$3
\&  }
\&  if ($1 == 6) then {
\&    "\\s-2R2\\s+2" above at $2,$3
\&  }
\&  if ($1 == 7) then {
\&    "\\s-2R3\\s+2" above at $2,$3
\&  }
\&  if ($1 == 8) then {
\&    "\\s-2S\\s+2" above at $2,$3 
\&  }
\&%   
\&define dashedbar % #(X,Y)
\&  line from $1,0 to $1,$2 dashed
\&  line from $1,$2 to $1+9,$2 dashed
\&  line from $1+9,$2 to $1+9,0 dashed
\&%
\&define abar % #(X,Y)
\&  line from $1,0 to $1,$2
\&  line from $1,$2 to $1+9,$2
\&  line from $1+9,$2 to $1+9,0
\&%
\&define bar_succ % #(load,y,junk)
\&  abar(curx,$2)
\&  write_name(name,curx+5,$2)
\&  curx = curx + jump
\&  if (Maxy < $2) then { Maxy = $2 }
\&%
\&define bar_goodness % #(load,y,junk)
\&  abar(curx,$3-100)
\&  write_name(name,curx+5,$3-100)
\&  curx = curx + jump
\&  if (Maxy < ($3-100) ) then { Maxy = $3-100 }
\&%
\&define bar_avmax % #(load,average,max)
\&  abar(curx,$2)
\&  dashedbar(curx,$3)
\&  write_name(name,curx+5,$3)
\&  curx = curx+jump
\&  if (Maxy < $3) then { Maxy = $3 }
\&%
\&define bar_set % #(filename,jump,startX,name,function)
\&  jump = $2
\&  curx = $3
\&  name = $4
\&  copy $1 thru bar_$5
\&%
\&define setload % #(load, junk, junk
\&  ticks bot in 0.0 at ((2*count+1)*jump-gap/2)/2 "$1"
\&  count = count + 1
\&%
\&define mkgraphTiming % #(Timing,Name,file,function,number,ylabel,dir,toplable)
\&  Maxy = 0.0
\&  Nbars = 3
\&  start = 1
\&  gap = 15 
\&  jump = Nbars * 10 + gap
\&  bar_set("$7.Global.$1.$3.result",jump,start,1,$4)
\&  bar_set("$7.Hybrid.$1.$3.result",jump,start + 10,2,$4)
\&  bar_set("$7.Local.$1.$3.result",jump,start + 2*10,3,$4)
\&  line from 0,0 to jump*4-gap,0
\&  count = 0
\&  copy "$7.Local.$1.$3.result" through setload
\&  label top "\\fI$5)\\fP Timing = $2, $8" up .2
\&  label left $6 unaligned up 1.8 right .2
\&  label bot "load"  
\&  frame invis ht 3 wid 3 left solid bot solid
\&%
\&graph A
\&   mkgraphTiming(Random1500,Random-1500 ms,succ,succ,i,"SR (%)",\\
\&	result.SQ_MESH.Fail1.S3.R0,Square mesh)
\&.G2
.ft
.ps 10
.vs 12
.DE
.G1 2.5i
define write_name % #(code,X,Y)
  if ($1 == 1) then {
    "\s-2G\s+2" above at $2,$3 
  }
  if ($1 == 2) then {
    "\s-2H\s+2" above at $2,$3
  }
  if ($1 == 3) then {
    "\s-2L\s+2" above at $2,$3
  }
  if ($1 == 4) then {
    "\s-2I\s+2" above at $2,$3
  }
  if ($1 == 5) then {
    "\s-2R1\s+2" above at $2,$3
  }
  if ($1 == 6) then {
    "\s-2R2\s+2" above at $2,$3
  }
  if ($1 == 7) then {
    "\s-2R3\s+2" above at $2,$3
  }
  if ($1 == 8) then {
    "\s-2S\s+2" above at $2,$3 
  }
%   
define dashedbar % #(X,Y)
  line from $1,0 to $1,$2 dashed
  line from $1,$2 to $1+9,$2 dashed
  line from $1+9,$2 to $1+9,0 dashed
%
define abar % #(X,Y)
  line from $1,0 to $1,$2
  line from $1,$2 to $1+9,$2
  line from $1+9,$2 to $1+9,0
%
define bar_succ % #(load,y,junk)
  abar(curx,$2)
  write_name(name,curx+5,$2)
  curx = curx + jump
  if (Maxy < $2) then { Maxy = $2 }
%
define bar_goodness % #(load,y,junk)
  abar(curx,$3-100)
  write_name(name,curx+5,$3-100)
  curx = curx + jump
  if (Maxy < ($3-100) ) then { Maxy = $3-100 }
%
define bar_avmax % #(load,average,max)
  abar(curx,$2)
  dashedbar(curx,$3)
  write_name(name,curx+5,$3)
  curx = curx+jump
  if (Maxy < $3) then { Maxy = $3 }
%
define bar_set % #(filename,jump,startX,name,function)
  jump = $2
  curx = $3
  name = $4
  copy $1 thru bar_$5
%
define setload % #(load, junk, junk
  ticks bot in 0.0 at ((2*count+1)*jump-gap/2)/2 "$1"
  count = count + 1
%
define mkgraphTiming % #(Timing,Name,file,function,number,ylabel,dir,toplable)
  Maxy = 0.0
  Nbars = 3
  start = 1
  gap = 15 
  jump = Nbars * 10 + gap
  bar_set("$7.Global.$1.$3.result",jump,start,1,$4)
  bar_set("$7.Hybrid.$1.$3.result",jump,start + 10,2,$4)
  bar_set("$7.Local.$1.$3.result",jump,start + 2*10,3,$4)
  line from 0,0 to jump*4-gap,0
  count = 0
  copy "$7.Local.$1.$3.result" through setload
  label top "\fI$5)\fP Timing = $2, $8" up .2
  label left $6 unaligned up 1.8 right .2
  label bot "load"  
  frame invis ht 3 wid 3 left solid bot solid
%
graph A
   mkgraphTiming(Random1500,Random-1500 ms,succ,succ,i,"SR (%)",result.SQ_MESH.Fail1.S3.R0,Square mesh)
.G2
.KE
.KS
.PP
This is a graph donated by Bruce Lilly, after it demonstrated a couple 
.CW grap
bugs and incompatibilities with DWB
.CW grap .
But mostly I include it because it's a cool timing diagram, although I
have no idea for what.  I shrunk it for this example, so this version
is a little more cramped than his.  Remove the 4 that follows the .G1
to see the diagram in its full glory.
.DS
.ft CW
.ps 8
.vs 10
\&.G1 4
\&.ps 14
\&frame ht 5 wid 6 top invis right invis left invis bot invis
\&ticks off
\&coord x -21, 21 y 0, 70
\&line dashed from (0,0) to (0,68)
\&line dotted from (-11,0) to (-11,70)
\&line dotted from (11,0) to (11,70)
\&"clock" rjust at -21, 3.5
\&"data" rjust at -21, 35
\&"timing reference" below at 0, -1
\&"recovery window" at 0, 70
\&arrow from (-6,70) to (-10,70)
\&arrow from (6,70) to (10,70)
\&"``perfect'' data" at 0, 13.5
\&"jitter" at 0, 23.5
\&"timing offset" at 0, 38.3
\&"timing offset + jitter" at 0, 58.3
\&.\\"	clock
\&draw solid
\&[inline data elided]
\&.\\"	perfect data
\&new solid
\&[inline data elided]
\&new solid
\&[inline data elided]
\&.\\"	data with jitter +-3 ns
\&new solid
\&[inline data elided]
\&new solid
\&[inline data elided]
\&.\\"	+3 ns
\&new dashed
\&[inline data elided]
\&new dashed
\&[inline data elided]
\&.\\"	-3 ns
\&new dashed
\&[inline data elided]
\&new dashed
\&[inline data elided]
\&.\\"	timing offset +3 ns
\&new solid
\&[inline data elided]
\&new solid
\&[inline data elided]
\&.\\"	timing offset -3 ns
\&new solid
\&[inline data elided]
\&new solid
\&[inline data elided]
\&.\\"	+3 ns timing offset +-3 ns jitter
\&.\\"	+3 ns timing offset
\&new solid
\&[inline data elided]
\&new solid
\&[inline data elided]
\&.\\"	-3 ns jitter around +3 ns timing offset
\&new dashed
\&[inline data elided]
\&new dashed
\&[inline data elided]
\&.\\"	+3 ns jitter around +3 ns timing offset
\&new dashed
\&[inline data elided]
\&new dashed
\&[inline data elided]
\&.\\"	-3 ns timing offset +-3 ns jitter
\&.\\"	-3 ns timing offset
\&new solid
\&[inline data elided]
\&new solid
\&[inline data elided]
\&.\\"	-3 ns jitter around -3 ns timing offset
\&new dashed
\&[inline data elided]
\&new dashed
\&[inline data elided]
\&.\\"	+3 ns jitter around -3 ns timing offset
\&new dashed
\&[inline data elided]
\&new dashed
\&[inline data elided]
\&.ps
\&.G2
.ft
.DE
.G1 4
.ps 14
frame ht 5 wid 6 top invis right invis left invis bot invis
ticks off
coord x -21, 21 y 0, 70
line dashed from (0,0) to (0,68)
line dotted from (-11,0) to (-11,70)
line dotted from (11,0) to (11,70)
"clock" rjust at -21, 3.5
"data" rjust at -21, 35
"timing reference" below at 0, -1
"recovery window" at 0, 70
arrow from (-6,70) to (-10,70)
arrow from (6,70) to (10,70)
"``perfect'' data" at 0, 13.5
"jitter" at 0, 23.5
"timing offset" at 0, 38.3
"timing offset + jitter" at 0, 58.3
.\"	clock
draw solid
-21, 7
-16, 0
-2.5, 0
2.5, 7
16, 7
21, 0
.\"	perfect data
new solid
-21, 17
-16, 10
16, 10
21, 17
new solid
-21, 10
-16, 17
16, 17
21, 10
.\"	data with jitter +-3 ns
new solid
-21, 27
-16, 20
16, 20
21, 27
new solid
-21, 20
-16, 27
16, 27
21, 20
.\"	+3 ns
new dashed
-21, 27
-18, 27
-13, 20
19, 20
21, 22.8
new dashed
-21, 20
-18, 20
-13, 27
19, 27
21, 24.2
.\"	-3 ns
new dashed
-21, 22.8
-19, 20
13, 20
18, 27
21, 27
new dashed
-21, 24.2
-19, 27
13, 27
18, 20
21, 20
.\"	timing offset +3 ns
new solid
-21, 37
-18, 37
-13, 30
19, 30
21, 32.8
new solid
-21, 30
-18, 30
-13, 37
19, 37
21, 34.2
.\"	timing offset -3 ns
new solid
-21, 44.2
-19, 47
13, 47
18, 40
21, 40
new solid
-21, 42.8
-19, 40
13, 40
18, 47
21, 47
.\"	+3 ns timing offset +-3 ns jitter
.\"	+3 ns timing offset
new solid
-21, 57
-18, 57
-13, 50
19, 50
21, 52.8
new solid
-21, 50
-18, 50
-13, 57
19, 57
21, 54.2
.\"	-3 ns jitter around +3 ns timing offset
new dashed
-21, 57
-15, 57
-10, 50
21, 50
new dashed
-21, 50
-15, 50
-10, 57
21, 57
.\"	+3 ns jitter around +3 ns timing offset
new dashed
-21, 57
-16, 50
16, 50
21, 57
new dashed
-21, 50
-16, 57
16, 57
21, 50
.\"	-3 ns timing offset +-3 ns jitter
.\"	-3 ns timing offset
new solid
-21, 64.2
-19, 67
13, 67
18, 60
21, 60
new solid
-21, 62.8
-19, 60
13, 60
18, 67
21, 67
.\"	-3 ns jitter around -3 ns timing offset
new dashed
-21, 67
10, 67
15, 60
21, 60
new dashed
-21, 60
10, 60
15, 67
21, 67
.\"	+3 ns jitter around -3 ns timing offset
new dashed
-21, 60
-16, 67
16, 67
21, 60
new dashed
-21, 67
-16, 60
16, 60
21, 67
.ps
.G2
.\" "
.KE
.KS
Bruce Lilly also suggests this example.  He says:
.QP
I've attached a small data file and simple grap specification which shows
one way to handle missing data (and perhaps also how to ignore a column
header row in a data file). The data is annual US bicyclist fatalities as
published by the National Highway Transportation Safety Administration
.I http://www.nhtsa.dot.gov/people/ncsa/factshet.html ; (
the \*Qfact sheets\*U for
\*Qpedalcyclists\*U for 1998 and for 1993) and by the National Center for
Injury Prevention and Control
.I http://www.cdc.gov/ncipc/osp/us9693/mvpctr.htm ; (
change the numbers for
different years). CDC data hasn't yet been published for 1997 or 1998.
Don't ask me why two groups of bureaucrats in the US Federal Government
can't agree on the numbers.  The data is, of course, public information,
and there's no reason why you can't use the trivial grap
specification (though you might wish to embellish it).
.LP
I did embellish it by adding labels and a key.
.DS
.CW
\&.G1
\&label top "Bicycling Deaths by Year"
\&label left "Deaths" left 0.2
\&label bottom "Year"
\&copy "cy_fatal.d" through {
\&	# ignore missing data (zero or negative values 
\&	# used as placeholders). It also happens to ignore column
\&	# header rows in data.
\&	if $2 > 0 then {square at $1,$2 }
\&	if $3 > 0 then {bullet at $1,$3 }
\&}
\&square at 1993, 925
\&"NHTSA data" ljust at 1993.5, 925
\&bullet at 1993, 900
\&"CDC data" ljust at 1993.5, 900
\&line from 1992.5,940 to 1998,940
\&line from 1998,940 to 1998,890
\&line from 1998,890 to 1992.5, 890
\&line from 1992.5, 890 to 1992.5,940
\&.G2
.DE
.G1
label top "Bicycling Deaths by Year"
label left "Deaths" left 0.2
label bottom "Year"
copy "cy_fatal.d" through {
	# ignore missing data (zero or negative values
	# used as placeholders).  It also happens to ignore column
	# header rows in data.
	if $2 > 0 then {square at $1,$2 }
	if $3 > 0 then {bullet at $1,$3 }
}
square at 1993, 925
"NHTSA data" ljust at 1993.5, 925
bullet at 1993, 900
"CDC data" ljust at 1993.5, 900
line from 1992.5,940 to 1998,940
line from 1998,940 to 1998,890
line from 1998,890 to 1992.5, 890
line from 1992.5, 890 to 1992.5,940
.G2
.KE
.KS
This example shows off the new automatic tick generation for named
coordinate systems.  It is a re-plot of earlier data.  The automatic
ticks do not look great here because they are generated on a
logarithmic axis.  Still, it means that the graph can be generated
without constants in the grap code.
.DS
.CW
\&.G1
\&define square {"\\s-2\\(sq\\s0"}
\&frame ht 3 wid 3.5
\&label left "Population in Millions (Plotted as \(bu)"
\&label bot "Rank in Population"
\&label right "Representatives (Plotted as \(sq)"
\&coord pop log y
\&coord rep log y
\&ticks left out auto pop
\&ticks bot out auto pop
\&ticks right out auto rep
\&thisrank = 50
\&copy "states.d" thru {
\&	bullet at pop thisrank,$3/1e6
\&	square at rep thisrank,$2
\&	thisrank = thisrank -1
\&}
\&.G2
.DE
.G1
define square {"\s-2\(sq\s0"}
frame ht 3 wid 3.5
label left "Population in Millions (Plotted as \(bu)"
label bot "Rank in Population"
label right "Representatives (Plotted as \(sq)"
coord pop log y
coord rep log y
ticks left out auto pop
ticks bot out auto pop
ticks right out auto rep
thisrank = 50
copy "states.d" thru {
	bullet at pop thisrank,$3/1e6
	square at rep thisrank,$2
	thisrank = thisrank -1
}
.G2
.KE
.KS
.PP
This is a demonstration of the new line clipping.  The right graph is
a detail of the left, created by simply respecifying the coordinate
limits.  (The region plotted in the right graph is the dotted
rectangle in the left.)  Note that the data is clipped leaving the
area plotted and returning.  The data is the 400 Meter Run Olympic
data from before.
.EQ
delim off
.EN
.DS
.ft CW
\&graph Main
\&frame invis ht 2 wid 2.5 left solid bot solid
\&label left "Time (in seconds)"
\&label bot "Olympic 400 Meter Run: Winning Times" right 1.75
\&coord x 1894, 1994 y 42, 56
\&ticks left out at 44 "44", 46, 48 "48", 50, 52 "52", 54
\&ticks bot in from 1900 to 1980 by 20
\&draw solid
\&copy "400mpairs.d"
\&bar (1908,46), (1940,49) dashed
\&# detail graph
\&graph Detail with .w at Main.Frame.e +(0.1,0)
\&frame dashed ht 2 wid 2.5 right solid bot solid
\&label right "Time (in seconds)" 
\&ticks left off
\&ticks right on
\&ticks bot in
\&draw solid
\&copy "400mpairs.d"
\&coord x 1908,1942 y 45,49
.ft
.DE
.EQ
delim $$
.EN
.G1
graph Main
frame invis ht 2 wid 2.5 left solid bot solid
label left "Time (in seconds)"
label bot "Olympic 400 Meter Run: Winning Times" right 1.75
coord x 1894, 1994 y 42, 56
ticks left out at 44 "44", 46, 48 "48", 50, 52 "52", 54
ticks bot in from 1900 to 1980 by 20
draw solid
copy "400mpairs.d"
bar (1908,46), (1940,49) dashed
# detail graph
graph Detail with .w at Main.Frame.e +(0.1,0)
frame dashed ht 2 wid 2.5 right solid bot solid
label right "Time (in seconds)" 
ticks left off
ticks right on
ticks bot in
draw solid
copy "400mpairs.d"
coord x 1908,1942 y 45,49
.G2
.KE
.KS
.PP
Revisiting the boy heights example to demonstrate some other 
.CW grap
features.  New to this version is the ability to use x and y directly
as variable names anywhere but a 
.CW coord
statement.  Fixed as of release
1.10 is the ability to start a new line of the named style (or the
default if no name is given) using the 
.CW new 
statement.  The variable 
.CW y
is directly used in the computation of the regression, and each dashed
error bar is drawn using the conf line style.  Otherwise this is the
earlier graph.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&label left "Heights in Feet"
\&label bot "Heights of Boys in the US Ages 2-18"
\&cmpft = 12
\&minx = 1e12; maxx = -1e12
\&n = sigx = sigx2 = sigy = sigxy = 0;
\&draw conf dashed
\&copy "boyhts.d" thru {
\&	new conf
\&	next conf at $1, $2/cmpft
\&	next conf at $1, $4/cmpft
\&	y = $3 / cmpft
\&	bullet at $1, y
\&	n = n+1
\&	sigx = sigx + $1; sigx2 = sigx2 + $1 * $1
\&	sigy = sigy + y; sigxy = sigxy + $1*y
\&	minx = min(minx,$1); maxx = max(maxx,$1);
\&}
\&slope = ( n*sigxy - sigx* sigy) / (n*sigx2 - sigx * sigx)
\&inter = ( sigy - slope * sigx) / n
\&line from minx, slope * minx+inter to maxx, slope * maxx + inter
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
label left "Heights in Feet"
label bot "Heights of Boys in the US Ages 2-18"
cmpft = 12
minx = 1e12; maxx = -1e12
n = sigx = sigx2 = sigy = sigxy = 0;
draw conf dashed
copy "boyhts.d" thru {
	new conf
	next conf at $1, $2/cmpft
	next conf at $1, $4/cmpft
	y = $3 / cmpft
	bullet at $1, y
	n = n+1
	sigx = sigx + $1; sigx2 = sigx2 + $1 * $1
	sigy = sigy + y; sigxy = sigxy + $1*y
	minx = min(minx,$1); maxx = max(maxx,$1);
}
slope = ( n*sigxy - sigx* sigy) / (n*sigx2 - sigx * sigx)
inter = ( sigy - slope * sigx) / n
line from minx, slope * minx+inter to maxx, slope * maxx + inter
.G2
.KE
.KS
.PP
Some fun with embedded pic and troff to show that they work.  The
plotting points are made by a troff font change to Helvetica, drawing
an \*Qx\*U in grap, then a pic box around it, a second troff font
change and another grap label.  This example will almost certainly fail
under TeX.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&coord x 5,35 y 5, 35
\&ticks off
\&copy until "END" thru {
\&.	ft H
\&	"x" at $1, $2
\&	pic box ht 0.1 wid 0.1 at Here
\&.	ft R
\&	"" "$3" below at $1, $2
\&}
\&10 10 here's
\&20 20 some
\&30 30 pic/troff
\&END
\&.G2
.DE
.EQ
delim $$
.EN
.ft
.G1
coord x 5,35 y 5, 35
ticks off
copy until "END" thru {
.	ft H
	"x" at $1, $2
	pic box ht 0.1 wid 0.1 at Here
.	ft R
	"" "$3" below at $1, $2
}
10 10 here's
20 20 some
30 30 pic/troff
END
.G2
.KE
.KS
.PP
.CW grap
is now 
.I much 
more context sensitive in how it picks out keywords.  There are still
some places where it will resolutely not allow variables with keyword
names, but it's enormously better about it.  Here's a short somewhat
pathological example.  I couldn't decide which for loop was less
readable, so I used both.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&from=0
\&to = 10
\&ht =3
\&wid = 5
\&frame ht ht wid wid
\&for i from from to to do {
\&   delta at i, i
\&}
\&for j = from to to do {
\&   bullet at to - j, j
\&}
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
from=0
to = 10
ht =3
wid = 5
frame ht ht wid wid
for i from from to to do {
   delta at i, i
}
for j = from to to do {
   bullet at to - j, j
}
.G2
.KE
.bp
.KS
.PP
At the request of Bruce Lilly, coordinate spaces and variables now
have distinct name spaces, and those names spaces can (usually)
overlap both each other and keywords.  The result is that things like
this are legal.
.DS
.ft CW
\&.G1
\&from = 0
\&to = 10
\&new next dotted delta
\&for next from from to to do {
\&	next next at next next, next
\&}
\&ticks left on next
\&ticks bot on next
\&.G2
.ft
.DE
.G1
from = 0
to = 10
new next dotted delta
for next from from to to do {
	next next at next next, next
}
ticks left on next
ticks bot on next
.G2
.PP
I think we're now ready for the first obfuscated 
.CW grap
contest.  The following is a more readable version:
.DS
.ft CW
\&.G1
\&start = 0
\&finish = 10
\&new line_style dotted delta
\&coord coord_space
\&for i from start to finish do {
\&	next line_style at coord_space i, i
\&}
\&ticks left on coord_space
\&ticks bot on coord_space
\&.G2
.ft
.DE
.KE
.KS
One of the few things that one couldn't do under recent versions of 
.CW grap
was redefining keywords.  Now you can.  Here's an example that
redefines the bar keyword.  This also demonstrates the new undefine
keyword that restores the original bar semantics.
.DS
.ft CW
\&.G1
\&define bar { "_" } 
\&for i = 1 to 10 do {
\&	bar at i,i
\&}
\&undefine bar
\&bar up 5 ht 3
\&.G2
.G1
define bar { "_" } 
for i = 1 to 10 do {
	bar at i,i
}
undefine bar
bar up 5 ht 3
.G2
.DE
.KE
.KS
.PP
Bruce Lilly tells me that DWB 
.CW grap
defines some macros to make embedding pic code easier.  The macros are
named
.CW x_
.I coordname ,
.CW y_
.I coordname ,
and
.CW xy_
.I coordname .
The first 2 return a pic location corresponding to that x or y
coordinate in the given name space.  The third generates a pair of
coordinates in the given coordinate space.  The default coordinate
space is given by
.CW x_gg ,
.CW y_gg ,
and
.CW xy_gg .
If you define a coordinate space named gg, the macros will map one or
the other, but I don't know which.
.PP
DWB 
.CW grap
may use these as part of their implementation.  They're an extra
feature for compatibility here.
.PP
Here's a simple example of using these.  Note that the fors loop are 
pic for loops.  You don't have access to grap variables from pic.
.DS
.ft CW
\&.G1
\&coord test x 0, 10 y 0, 10
\&coord x 0, 20 y 0, 20
\&frame
\&ticks bot on test
\&ticks left on test 
\&pic for i = 0 to 9 do {
\&pic "x" at Frame.Origin + xy_test(i,i)
\&pic }
\&pic for i = 0 to 9 do {
\&pic "o" at Frame.Origin + xy_gg(1,i)
\&pic }
\&.G2
.G1
coord test x 0, 10 y 0, 10
coord x 0, 20 y 0, 20
frame
ticks bot on test
ticks left on test 
pic for i = 0 to 9 do {
pic "x" at Frame.Origin + xy_test(i,i)
pic }
pic for i = 0 to 9 do {
pic "o" at Frame.Origin + xy_gg(1,i)
pic }
.G2
.DE
.KE
.KS
.PP
A demo of 
.I grap 's
ability to directly manipulate label and plotting sizes.  The data is all in
the graph specification.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame ht 2 wid 2
\&coord x 0,100 y 0,100
\&grid bot dotted from 20 to 80 by 20 "%g" size +5
\&grid left dotted from 20 to 80 by 20 "%g" size -3
\&
\&"Text above" above at 50,50
\&"Text rjust   " rjust at 50,50
\&bullet at 80,90
\&vtick at 80,80
\&box at 80,70
\&times at 80,60
\&
\&circle at 50,50
\&circle at 50,80 radius .25
\&line dashed from 10,90 to 30,90
\&arrow from 10,70 to 30,90
\&
\&draw A solid
\&draw B dashed delta size 15
\&next A at 10,10
\&next B at 10,20
\&next A at 50,20
\&next A at 90,10
\&next B at 50,30
\&next B at 90,30
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame ht 2 wid 2
coord x 0,100 y 0,100
grid bot dotted from 20 to 80 by 20 "%g" size +5
grid left dotted from 20 to 80 by 20 "%g" size -3

"Text above" above at 50,50
"Text rjust   " rjust at 50,50
bullet at 80,90
vtick at 80,80
box at 80,70
times at 80,60

circle at 50,50
circle at 50,80 radius .25
line dashed from 10,90 to 30,90
arrow from 10,70 to 30,90

draw A solid
draw B dashed delta size 15
next A at 10,10
next B at 10,20
next A at 50,20
next A at 90,10
next B at 50,30
next B at 90,30
.G2
.KE
.bp
.EQ
delim $$
.EN
.PP
.KS
.PP
A gratuitous color graph.  Don't ever produce anything this ugly.  The
data is the 400m times used earlier.  There's a circle to show the color and
fillcolor attributes.  I've also added a thickness to one line and the circle.
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&frame invis ht 2 wid 3 left solid color "blue" \\
\& 	bot solid color "orange"
\&label left "Time (in seconds)" left .15
\&label bot "Olympic 400 Meter Run: Winning Times"
\&coord x 1894, 1994 y 42, 56
\&ticks left out at 44 , 46 "", 48, 50 "", 52, 54 ""
\&ticks bot in from 1900 to 1980 by 20
\&grid bot ticks off  color "yellow" from 1900 to 1980 by 20
\&grid left ticks off  color "yellow" at 44, 46, 48, 50, 52, 54 
\&draw solid color "green" delta color "violet"
\&copy "400mpairs.d"
\&new color "red" thickness 2.5
\&copy "400wpairs.d"
\&"Women" size -3 at 1958,52
\&"Men" size -3 at 1910,47
\&circle at 1940, 52 rad 0.25 color "blue" fillcolor "red" \\
\&	fill 0.5 thickness 2
\&.G2
.ft
.DE
.EQ
delim $$
.EN
.G1
frame invis ht 2 wid 3 left solid color "blue" \
	bot solid color "orange"
label left "Time (in seconds)" left .15
label bot "Olympic 400 Meter Run: Winning Times"
coord x 1894, 1994 y 42, 56
ticks left out at 44 , 46 "", 48, 50 "", 52, 54 ""
ticks bot in from 1900 to 1980 by 20
grid bot ticks off  color "yellow" from 1900 to 1980 by 20
grid left ticks off  color "yellow" at 44, 46, 48, 50, 52, 54 
draw solid color "green" delta color "violet"
copy "400mpairs.d"
new color "red" thickness 2.5
copy "400wpairs.d"
"Women" size -3 at 1958,52
"Men" size -3 at 1910,47
circle at 1940, 52 rad 0.25 color "blue" fillcolor "red" \
	fill 0.5 thickness 2
.G2
.KE
.bp
.PP
Some people have tripped over 
.CW grap 's
fairly limited string manipulation capabilities.  Simply 
.CW grap
can only compare two quoted strings for equality.  Strings cannot be
assigned to variables.  Surprisingly, when combined with macros, that's
enough to do simple data selection, but not much more.  Here's an
example.
.KS
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&copy until "END" thru {
\&    if ( "$1" == "yes" ) then {
\&        next at $2, $3
\&    }
\&}
\&yes 1 1
\&yes 2 2
\&no 3 3
\&yes 4 4
\&yes 5 5
\&END
\&.G2
.ft
.DE
.G1
copy until "END" thru {
if ( "$1" == "yes" ) then {
	next at $2, $3
}
}
yes 1 1
yes 2 2
no 3 3
yes 4 4
yes 5 5
END
.G2
.KE
.LP
Note that while data files can contain quotes, putting quotes in the
data file will 
.B not 
collect words into strings containing whitespace; 
.CW grap
splits lines of data files into words separated by whitespace.
.CW Grap 's 
macro substitution and line splitting are very literal and know nothing
about the language structure.  Overall, if you're planning anything more
complex than conditionals based on the contents of a single word
parameter to a macro call, do it outside 
.CW grap .
.CW Perl
and other scripting languages make complex text manipulations very easy.
Here's the same example with quotes in the file; notice the change in the
expression in the 
.CW if .
.KS
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&copy until "END" thru {
\&    if ( $1 == "yes" ) then {
\&        next at $2, $3
\&    }
\&}
\&"yes" 1 1
\&"yes" 2 2
\&"no" 3 3
\&"yes" 4 4
\&"yes" 5 5
\&END
\&.G2
.ft
.DE
.G1
copy until "END" thru {
if ( $1 == "yes" ) then {
	next at $2, $3 
}
}
"yes" 1 1
"yes" 2 2
"no" 3 3
"yes" 4 4
"yes" 5 5
END
.G2
.KE
.bp
.LP
This demonstrates the 
.CW grap
features for manipulating dates by plotting a histogram of automobile
gas mileage.  The fields of the data are a date in yyymmdd format, an
odometer reading and the number of gallons on fill up.  The 
.CW strptime
function is used to convert the ad hoc date format into a plottable
number, and 
.CW strptime
is used to label ticks.
.KS
.EQ
delim off
.EN
.DS
.ft CW
\&.G1
\&max_mpg = last_date = last_miles = mn = mx = 0
\&copy until "END" thru { 
\&  # parse the date into seconds
\&  dt = strptime("%Y%m%d", "$1")
\&  if mn == 0 || dt < mn then { mn = dt }
\&  if mx == 0 || dt > mx then { mx = dt }
\&  if last_miles != 0 then { 
\&  	mpg = ($2 - last_miles)/$3
\&	if mpg > max_mpg then { max_mpg = mpg }
\&  	bar up (last_date + dt) / 2 ht mpg wid dt -last_date
\&  }
\&  last_miles = $2; last_date = dt 
\&}
\&20100623 34794 9.845
\&[...]
\&20111119 42802 9.539
\&END
\&for t from mn to mx by (mx - mn )/3 do {
\&	tick bot at t strftime("%Y-%m-%d", t)
\&}
\&label left "Miles per gallon"
\&label bot "Dates"
\&.G2
.ft
.DE
.G1
max_mpg = last_date = last_miles = mn = mx = 0
copy until "END" thru { 
  # parse the date into seconds
  dt = strptime("%Y%m%d", "$1")
  if mn == 0 || dt < mn then { mn = dt }
  if mx == 0 || dt > mx then { mx = dt }
  if last_miles != 0 then { 
  	mpg = ($2 - last_miles)/$3
	if mpg > max_mpg then { max_mpg = mpg }
  	bar up (last_date + dt) / 2 ht mpg wid dt -last_date
  }
  last_miles = $2; last_date = dt 
}
20100623 34794 9.845 
20100710 35066 9.804
20100728 35339 9.785
20100811 35623 10.026
20100826 35919 10.086
20100912 36192 9.536
20101001 36472 9.759
20101024 36737 9.848
20101113 37004 9.827
20101129 37257 9.806
20101218 37521 10.211
20110108 37774 9.868
20110122 38036 10.295
20110208 38293 9.693
20110220 38564 9.567
20110306 38817 9.577
20110325 39087 10.090
20110406 39350 9.893
20110422 39620 9.975
20110507 39913 10.089
20110522 40149 8.428
20110614 40411 10.007
20110702 40696 9.842
20110719 40982 10.219
20110806 41224 8.710
20110828 41510 9.775
20110917 41745 8.142
20111005 42018 9.841
20111019 42287 9.886
20111108 42545 9.732
20111119 42802 9.539
END
for t from mn to mx by (mx - mn )/3 do {
	tick bot at t strftime("%Y-%m-%d", t)
}
label left "Miles per gallon"
label bot "Dates"
.G2
.KE