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 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762
|
R version 3.1.1 RC (2014-07-04 r66081) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> pkgname <- "grDevices"
> source(file.path(R.home("share"), "R", "examples-header.R"))
> options(warn = 1)
> library('grDevices')
>
> base::assign(".oldSearch", base::search(), pos = 'CheckExEnv')
> cleanEx()
> nameEx("Devices")
> ### * Devices
>
> flush(stderr()); flush(stdout())
>
> ### Name: Devices
> ### Title: List of Graphical Devices
> ### Aliases: Devices device
> ### Keywords: device
>
> ### ** Examples
> ## Not run:
> ##D ## open the default screen device on this platform if no device is
> ##D ## open
> ##D if(dev.cur() == 1) dev.new()
> ## End(Not run)
>
>
> cleanEx()
> nameEx("Hershey")
> ### * Hershey
>
> flush(stderr()); flush(stdout())
>
> ### Name: Hershey
> ### Title: Hershey Vector Fonts in R
> ### Aliases: Hershey
> ### Keywords: aplot
>
> ### ** Examples
>
> Hershey
$typeface
[1] "serif" "sans serif" "script"
[4] "gothic english" "gothic german" "gothic italian"
[7] "serif symbol" "sans serif symbol"
$fontindex
[1] "plain" "italic" "bold" "bold italic"
[5] "cyrillic" "oblique cyrillic" "EUC"
$allowed
[,1] [,2]
[1,] 1 1
[2,] 1 2
[3,] 1 3
[4,] 1 4
[5,] 1 5
[6,] 1 6
[7,] 1 7
[8,] 2 1
[9,] 2 2
[10,] 2 3
[11,] 2 4
[12,] 3 1
[13,] 3 2
[14,] 3 3
[15,] 4 1
[16,] 5 1
[17,] 6 1
[18,] 7 1
[19,] 7 2
[20,] 7 3
[21,] 7 4
[22,] 8 1
[23,] 8 2
>
> ## for tables of examples, see demo(Hershey)
>
>
>
> cleanEx()
> nameEx("Japanese")
> ### * Japanese
>
> flush(stderr()); flush(stdout())
>
> ### Name: Japanese
> ### Title: Japanese characters in R
> ### Aliases: Japanese
> ### Keywords: aplot
>
> ### ** Examples
>
> require(graphics)
>
> plot(1:9, type = "n", axes = FALSE, frame = TRUE, ylab = "",
+ main = "example(Japanese)", xlab = "using Hershey fonts")
> par(cex = 3)
> Vf <- c("serif", "plain")
> text(4, 2, "\\#J244b\\#J245b\\#J2473", vfont = Vf)
> text(4, 4, "\\#J2538\\#J2563\\#J2551\\#J2573", vfont = Vf)
> text(4, 6, "\\#J467c\\#J4b5c", vfont = Vf)
> text(4, 8, "Japan", vfont = Vf)
> par(cex = 1)
> text(8, 2, "Hiragana")
> text(8, 4, "Katakana")
> text(8, 6, "Kanji")
> text(8, 8, "English")
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("Type1Font")
> ### * Type1Font
>
> flush(stderr()); flush(stdout())
>
> ### Name: Type1Font
> ### Title: Type 1 and CID Fonts
> ### Aliases: Type1Font CIDFont
> ### Keywords: device
>
> ### ** Examples
>
> ## This duplicates "ComputerModernItalic".
> CMitalic <- Type1Font("ComputerModern2",
+ c("CM_regular_10.afm", "CM_boldx_10.afm",
+ "cmti10.afm", "cmbxti10.afm",
+ "CM_symbol_10.afm"),
+ encoding = "TeXtext.enc")
>
> ## Not run:
> ##D ## This could be used by
> ##D postscript(family = CMitalic)
> ##D ## or
> ##D postscriptFonts(CMitalic = CMitalic) # once in a session
> ##D postscript(family = "CMitalic", encoding = "TeXtext.enc")
> ## End(Not run)
>
>
> cleanEx()
> nameEx("adjustcolor")
> ### * adjustcolor
>
> flush(stderr()); flush(stdout())
>
> ### Name: adjustcolor
> ### Title: Adjust Colors in One or More Directions Conveniently.
> ### Aliases: adjustcolor
>
> ### ** Examples
>
> ## Illustrative examples :
> opal <- palette("default")
> stopifnot(identical(adjustcolor(1:8, 0.75),
+ adjustcolor(palette(), 0.75)))
> cbind(palette(), adjustcolor(1:8, 0.75))
[,1] [,2]
[1,] "black" "#000000BF"
[2,] "red" "#FF0000BF"
[3,] "green3" "#00CD00BF"
[4,] "blue" "#0000FFBF"
[5,] "cyan" "#00FFFFBF"
[6,] "magenta" "#FF00FFBF"
[7,] "yellow" "#FFFF00BF"
[8,] "gray" "#BEBEBEBF"
>
> ## alpha = 1/2 * previous alpha --> opaque colors
> x <- palette(adjustcolor(palette(), 0.5))
>
> sines <- outer(1:20, 1:4, function(x, y) sin(x / 20 * pi * y))
> matplot(sines, type = "b", pch = 21:23, col = 2:5, bg = 2:5,
+ main = "Using an 'opaque ('translucent') color palette")
>
> x. <- adjustcolor(x, offset = c(0.5, 0.5, 0.5, 0), # <- "more white"
+ transform = diag(c(.7, .7, .7, 0.6)))
> cbind(x, x.)
x x.
[1,] "black" "#80808099"
[2,] "red" "#FF808099"
[3,] "green3" "#80FF8099"
[4,] "blue" "#8080FF99"
[5,] "cyan" "#80FFFF99"
[6,] "magenta" "#FF80FF99"
[7,] "yellow" "#FFFF8099"
[8,] "gray" "#FFFFFF99"
> op <- par(bg = adjustcolor("goldenrod", offset = -rep(.4, 4)), xpd = NA)
> plot(0:9, 0:9, type = "n", axes = FALSE, xlab = "", ylab = "",
+ main = "adjustcolor() -> translucent")
> text(1:8, labels = paste0(x,"++"), col = x., cex = 8)
> par(op)
>
> ## and
>
> (M <- cbind( rbind( matrix(1/3, 3, 3), 0), c(0, 0, 0, 1)))
[,1] [,2] [,3] [,4]
[1,] 0.3333333 0.3333333 0.3333333 0
[2,] 0.3333333 0.3333333 0.3333333 0
[3,] 0.3333333 0.3333333 0.3333333 0
[4,] 0.0000000 0.0000000 0.0000000 1
> adjustcolor(x, transform = M)
[1] "#000000FF" "#555555FF" "#444444FF" "#555555FF" "#AAAAAAFF" "#AAAAAAFF"
[7] "#AAAAAAFF" "#BEBEBEFF"
>
> ## revert to previous palette: active
> palette(opal)
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("as.raster")
> ### * as.raster
>
> flush(stderr()); flush(stdout())
>
> ### Name: as.raster
> ### Title: Create a Raster Object
> ### Aliases: is.raster as.raster as.raster.logical as.raster.numeric
> ### as.raster.character as.raster.matrix as.raster.array
> ### Keywords: dplot
>
> ### ** Examples
>
> # A red gradient
> as.raster(matrix(hcl(0, 80, seq(50, 80, 10)),
+ nrow = 4, ncol = 5))
[,1] [,2] [,3] [,4] [,5]
[1,] "#C54E6D" "#C54E6D" "#C54E6D" "#C54E6D" "#C54E6D"
[2,] "#E16A86" "#E16A86" "#E16A86" "#E16A86" "#E16A86"
[3,] "#FE86A1" "#FE86A1" "#FE86A1" "#FE86A1" "#FE86A1"
[4,] "#FFA2BC" "#FFA2BC" "#FFA2BC" "#FFA2BC" "#FFA2BC"
>
> # Vectors are 1-column matrices ...
> # character vectors are color names ...
> as.raster(hcl(0, 80, seq(50, 80, 10)))
[,1]
[1,] "#C54E6D"
[2,] "#E16A86"
[3,] "#FE86A1"
[4,] "#FFA2BC"
> # numeric vectors are greyscale ...
> as.raster(1:5, max = 5)
[,1]
[1,] "#333333"
[2,] "#666666"
[3,] "#999999"
[4,] "#CCCCCC"
[5,] "#FFFFFF"
> # locigal vectors are black and white ...
> as.raster(1:10 %% 2 == 0)
[,1]
[1,] "#000000"
[2,] "#FFFFFF"
[3,] "#000000"
[4,] "#FFFFFF"
[5,] "#000000"
[6,] "#FFFFFF"
[7,] "#000000"
[8,] "#FFFFFF"
[9,] "#000000"
[10,] "#FFFFFF"
>
> # ... unless nrow/ncol are supplied ...
> as.raster(1:10 %% 2 == 0, nrow = 1)
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] "#000000" "#FFFFFF" "#000000" "#FFFFFF" "#000000" "#FFFFFF" "#000000"
[,8] [,9] [,10]
[1,] "#FFFFFF" "#000000" "#FFFFFF"
>
> # Matrix can also be logical or numeric ...
> as.raster(matrix(c(TRUE, FALSE), nrow = 3, ncol = 2))
[,1] [,2]
[1,] "#FFFFFF" "#000000"
[2,] "#000000" "#FFFFFF"
[3,] "#FFFFFF" "#000000"
> as.raster(matrix(1:3/4, nrow = 3, ncol = 4))
[,1] [,2] [,3] [,4]
[1,] "#404040" "#404040" "#404040" "#404040"
[2,] "#808080" "#808080" "#808080" "#808080"
[3,] "#BFBFBF" "#BFBFBF" "#BFBFBF" "#BFBFBF"
>
> # An array can be 3-plane numeric (R, G, B planes) ...
> as.raster(array(c(0:1, rep(0.5, 4)), c(2, 1, 3)))
[,1]
[1,] "#008080"
[2,] "#FF8080"
>
> # ... or 4-plane numeric (R, G, B, A planes)
> as.raster(array(c(0:1, rep(0.5, 6)), c(2, 1, 4)))
[,1]
[1,] "#00808080"
[2,] "#FF808080"
>
> # subsetting
> r <- as.raster(matrix(colors()[1:100], ncol = 10))
> r[, 2]
[,1]
[1,] "aquamarine3"
[2,] "aquamarine4"
[3,] "azure"
[4,] "azure1"
[5,] "azure2"
[6,] "azure3"
[7,] "azure4"
[8,] "beige"
[9,] "bisque"
[10,] "bisque1"
> r[2:4, 2:5]
[,1] [,2] [,3] [,4]
[1,] "aquamarine4" "bisque3" "brown" "cadetblue"
[2,] "azure" "bisque4" "brown1" "cadetblue1"
[3,] "azure1" "black" "brown2" "cadetblue2"
>
> # assigning to subset
> r[2:4, 2:5] <- "white"
>
> # comparison
> r == "white"
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2,] FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
[3,] FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
[4,] FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
[5,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[6,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[7,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[8,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[9,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[10,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>
> ## Don't show:
> stopifnot(r[] == r,
+ identical(r[3:5], colors()[3:5]))
> r[2:4] <- "black"
> stopifnot(identical(r[1:4, 1], as.raster(c("white", rep("black", 3)))))
> ## End Don't show
>
>
>
> cleanEx()
> nameEx("axisTicks")
> ### * axisTicks
>
> flush(stderr()); flush(stdout())
>
> ### Name: axisTicks
> ### Title: Compute Pretty Axis Tick Scales
> ### Aliases: axisTicks .axisPars
> ### Keywords: dplot
>
> ### ** Examples
>
> ##--- Demonstrating correspondence between graphics'
> ##--- axis() and the graphics-engine agnostic axisTicks() :
>
> require("graphics")
> plot(10*(0:10)); (pu <- par("usr"))
[1] 0.6 11.4 -4.0 104.0
> aX <- function(side, at, ...)
+ axis(side, at = at, labels = FALSE, lwd.ticks = 2, col.ticks = 2,
+ tck = 0.05, ...)
> aX(1, print(xa <- axisTicks(pu[1:2], log = FALSE))) # x axis
[1] 2 4 6 8 10
> aX(2, print(ya <- axisTicks(pu[3:4], log = FALSE))) # y axis
[1] 0 20 40 60 80 100
>
> axisTicks(pu[3:4], log = FALSE, n = 10)
[1] 0 10 20 30 40 50 60 70 80 90 100
>
> plot(10*(0:10), log = "y"); (pu <- par("usr"))
Warning in xy.coords(x, y, xlabel, ylabel, log) :
1 y value <= 0 omitted from logarithmic plot
[1] 0.60 11.40 0.96 2.04
> aX(2, print(ya <- axisTicks(pu[3:4], log = TRUE))) # y axis
[1] 10 20 50 100
>
> plot(2^(0:9), log = "y"); (pu <- par("usr"))
[1] 0.6400000 10.3600000 -0.1083708 2.8176408
> aX(2, print(ya <- axisTicks(pu[3:4], log = TRUE))) # y axis
[1] 1 2 5 10 20 50 100 200 500
>
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("boxplot.stats")
> ### * boxplot.stats
>
> flush(stderr()); flush(stdout())
>
> ### Name: boxplot.stats
> ### Title: Box Plot Statistics
> ### Aliases: boxplot.stats
> ### Keywords: dplot
>
> ### ** Examples
>
> require(stats)
> x <- c(1:100, 1000)
> (b1 <- boxplot.stats(x))
$stats
[1] 1 26 51 76 100
$n
[1] 101
$conf
[1] 43.13921 58.86079
$out
[1] 1000
> (b2 <- boxplot.stats(x, do.conf = FALSE, do.out = FALSE))
$stats
[1] 1 26 51 76 100
$n
[1] 101
$conf
NULL
$out
numeric(0)
> stopifnot(b1 $ stats == b2 $ stats) # do.out = FALSE is still robust
> boxplot.stats(x, coef = 3, do.conf = FALSE)
$stats
[1] 1 26 51 76 100
$n
[1] 101
$conf
NULL
$out
[1] 1000
> ## no outlier treatment:
> boxplot.stats(x, coef = 0)
$stats
[1] 1 26 51 76 1000
$n
[1] 101
$conf
[1] 43.13921 58.86079
$out
numeric(0)
>
> boxplot.stats(c(x, NA)) # slight change : n is 101
$stats
[1] 1 26 51 76 100
$n
[1] 101
$conf
[1] 43.13921 58.86079
$out
[1] 1000
> (r <- boxplot.stats(c(x, -1:1/0)))
$stats
[1] 1.0 25.5 51.0 76.5 100.0
$n
[1] 103
$conf
[1] 43.06022 58.93978
$out
[1] 1000 -Inf Inf
> stopifnot(r$out == c(1000, -Inf, Inf))
>
> ## Don't show:
> ## Difference between quartiles and hinges :
> nn <- 1:17 ; n4 <- nn %% 4
> hin <- sapply(sapply(nn, seq), function(x) boxplot.stats(x)$stats[c(2,4)])
> q13 <- sapply(sapply(nn, seq), quantile, probs = c(1,3)/4, names = FALSE)
> m <- t(rbind(q13,hin))[, c(1,3,2,4)]
> dimnames(m) <- list(paste(nn), c("q1","lH", "q3","uH"))
> stopifnot(m[n4 == 1, 1:2] == (nn[n4 == 1] + 3)/4, # quart. = hinge
+ m[n4 == 1, 3:4] == (3*nn[n4 == 1] + 1)/4,
+ m[,"lH"] == ( (nn+3) %/% 2) / 2,
+ m[,"uH"] == ((3*nn+2)%/% 2) / 2)
> cm <- noquote(format(m))
> cm[m[,2] == m[,1], 2] <- " = "
> cm[m[,4] == m[,3], 4] <- " = "
> cm
q1 lH q3 uH
1 1.00 = 1.00 =
2 1.25 1.00 1.75 2.00
3 1.50 = 2.50 =
4 1.75 1.50 3.25 3.50
5 2.00 = 4.00 =
6 2.25 2.00 4.75 5.00
7 2.50 = 5.50 =
8 2.75 2.50 6.25 6.50
9 3.00 = 7.00 =
10 3.25 3.00 7.75 8.00
11 3.50 = 8.50 =
12 3.75 3.50 9.25 9.50
13 4.00 = 10.00 =
14 4.25 4.00 10.75 11.00
15 4.50 = 11.50 =
16 4.75 4.50 12.25 12.50
17 5.00 = 13.00 =
> ## End Don't show
>
>
>
>
> cleanEx()
> nameEx("check.options")
> ### * check.options
>
> flush(stderr()); flush(stdout())
>
> ### Name: check.options
> ### Title: Set Options with Consistency Checks
> ### Aliases: check.options
> ### Keywords: utilities programming
>
> ### ** Examples
>
> (L1 <- list(a = 1:3, b = pi, ch = "CH"))
$a
[1] 1 2 3
$b
[1] 3.141593
$ch
[1] "CH"
> check.options(list(a = 0:2), name.opt = "L1")
$a
[1] 0 1 2
$b
[1] 3.141593
$ch
[1] "CH"
> check.options(NULL, reset = TRUE, name.opt = "L1")
$a
[1] 1 2 3
$b
[1] 3.141593
$ch
[1] "CH"
>
>
>
> cleanEx()
> nameEx("chull")
> ### * chull
>
> flush(stderr()); flush(stdout())
>
> ### Name: chull
> ### Title: Compute Convex Hull of a Set of Points
> ### Aliases: chull
> ### Keywords: graphs
>
> ### ** Examples
>
> X <- matrix(stats::rnorm(2000), ncol = 2)
> chull(X)
[1] 61 442 165 899 697 446 975 656 232 557 938 295 495
> ## Not run:
> ##D # Example usage from graphics package
> ##D plot(X, cex = 0.5)
> ##D hpts <- chull(X)
> ##D hpts <- c(hpts, hpts[1])
> ##D lines(X[hpts, ])
> ## End(Not run)
>
>
>
> cleanEx()
> nameEx("cm")
> ### * cm
>
> flush(stderr()); flush(stdout())
>
> ### Name: cm
> ### Title: Unit Transformation
> ### Aliases: cm
> ### Keywords: dplot
>
> ### ** Examples
>
> cm(1) # = 2.54
[1] 2.54
>
> ## Translate *from* cm *to* inches:
>
> 10 / cm(1) # -> 10cm are 3.937 inches
[1] 3.937008
>
>
>
> cleanEx()
> nameEx("col2rgb")
> ### * col2rgb
>
> flush(stderr()); flush(stdout())
>
> ### Name: col2rgb
> ### Title: Color to RGB Conversion
> ### Aliases: col2rgb
> ### Keywords: color dplot
>
> ### ** Examples
>
> col2rgb("peachpuff")
[,1]
red 255
green 218
blue 185
> col2rgb(c(blu = "royalblue", reddish = "tomato")) # note: colnames
blu reddish
red 65 255
green 105 99
blue 225 71
>
> col2rgb(1:8) # the ones from the palette() (if the default)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
red 0 255 0 0 0 255 255 190
green 0 0 205 0 255 0 255 190
blue 0 0 0 255 255 255 0 190
>
> col2rgb(paste0("gold", 1:4))
[,1] [,2] [,3] [,4]
red 255 238 205 139
green 215 201 173 117
blue 0 0 0 0
>
> col2rgb("#08a0ff")
[,1]
red 8
green 160
blue 255
> ## all three kinds of color specifications:
> col2rgb(c(red = "red", hex = "#abcdef"))
red hex
red 255 171
green 0 205
blue 0 239
> col2rgb(c(palette = 1:3))
palette1 palette2 palette3
red 0 255 0
green 0 0 205
blue 0 0 0
>
> ##-- NON-INTRODUCTORY examples --
>
> grC <- col2rgb(paste0("gray", 0:100))
> table(print(diff(grC["red",]))) # '2' or '3': almost equidistant
[1] 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2
[38] 3 2 3 3 2 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 3 2 3 2 3
[75] 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3
2 3
45 55
> ## The 'named' grays are in between {"slate gray" is not gray, strictly}
> col2rgb(c(g66 = "gray66", darkg = "dark gray", g67 = "gray67",
+ g74 = "gray74", gray = "gray", g75 = "gray75",
+ g82 = "gray82", light = "light gray", g83 = "gray83"))
g66 darkg g67 g74 gray g75 g82 light g83
red 168 169 171 189 190 191 209 211 212
green 168 169 171 189 190 191 209 211 212
blue 168 169 171 189 190 191 209 211 212
>
> crgb <- col2rgb(cc <- colors())
> colnames(crgb) <- cc
> t(crgb) # The whole table
red green blue
white 255 255 255
aliceblue 240 248 255
antiquewhite 250 235 215
antiquewhite1 255 239 219
antiquewhite2 238 223 204
antiquewhite3 205 192 176
antiquewhite4 139 131 120
aquamarine 127 255 212
aquamarine1 127 255 212
aquamarine2 118 238 198
aquamarine3 102 205 170
aquamarine4 69 139 116
azure 240 255 255
azure1 240 255 255
azure2 224 238 238
azure3 193 205 205
azure4 131 139 139
beige 245 245 220
bisque 255 228 196
bisque1 255 228 196
bisque2 238 213 183
bisque3 205 183 158
bisque4 139 125 107
black 0 0 0
blanchedalmond 255 235 205
blue 0 0 255
blue1 0 0 255
blue2 0 0 238
blue3 0 0 205
blue4 0 0 139
blueviolet 138 43 226
brown 165 42 42
brown1 255 64 64
brown2 238 59 59
brown3 205 51 51
brown4 139 35 35
burlywood 222 184 135
burlywood1 255 211 155
burlywood2 238 197 145
burlywood3 205 170 125
burlywood4 139 115 85
cadetblue 95 158 160
cadetblue1 152 245 255
cadetblue2 142 229 238
cadetblue3 122 197 205
cadetblue4 83 134 139
chartreuse 127 255 0
chartreuse1 127 255 0
chartreuse2 118 238 0
chartreuse3 102 205 0
chartreuse4 69 139 0
chocolate 210 105 30
chocolate1 255 127 36
chocolate2 238 118 33
chocolate3 205 102 29
chocolate4 139 69 19
coral 255 127 80
coral1 255 114 86
coral2 238 106 80
coral3 205 91 69
coral4 139 62 47
cornflowerblue 100 149 237
cornsilk 255 248 220
cornsilk1 255 248 220
cornsilk2 238 232 205
cornsilk3 205 200 177
cornsilk4 139 136 120
cyan 0 255 255
cyan1 0 255 255
cyan2 0 238 238
cyan3 0 205 205
cyan4 0 139 139
darkblue 0 0 139
darkcyan 0 139 139
darkgoldenrod 184 134 11
darkgoldenrod1 255 185 15
darkgoldenrod2 238 173 14
darkgoldenrod3 205 149 12
darkgoldenrod4 139 101 8
darkgray 169 169 169
darkgreen 0 100 0
darkgrey 169 169 169
darkkhaki 189 183 107
darkmagenta 139 0 139
darkolivegreen 85 107 47
darkolivegreen1 202 255 112
darkolivegreen2 188 238 104
darkolivegreen3 162 205 90
darkolivegreen4 110 139 61
darkorange 255 140 0
darkorange1 255 127 0
darkorange2 238 118 0
darkorange3 205 102 0
darkorange4 139 69 0
darkorchid 153 50 204
darkorchid1 191 62 255
darkorchid2 178 58 238
darkorchid3 154 50 205
darkorchid4 104 34 139
darkred 139 0 0
darksalmon 233 150 122
darkseagreen 143 188 143
darkseagreen1 193 255 193
darkseagreen2 180 238 180
darkseagreen3 155 205 155
darkseagreen4 105 139 105
darkslateblue 72 61 139
darkslategray 47 79 79
darkslategray1 151 255 255
darkslategray2 141 238 238
darkslategray3 121 205 205
darkslategray4 82 139 139
darkslategrey 47 79 79
darkturquoise 0 206 209
darkviolet 148 0 211
deeppink 255 20 147
deeppink1 255 20 147
deeppink2 238 18 137
deeppink3 205 16 118
deeppink4 139 10 80
deepskyblue 0 191 255
deepskyblue1 0 191 255
deepskyblue2 0 178 238
deepskyblue3 0 154 205
deepskyblue4 0 104 139
dimgray 105 105 105
dimgrey 105 105 105
dodgerblue 30 144 255
dodgerblue1 30 144 255
dodgerblue2 28 134 238
dodgerblue3 24 116 205
dodgerblue4 16 78 139
firebrick 178 34 34
firebrick1 255 48 48
firebrick2 238 44 44
firebrick3 205 38 38
firebrick4 139 26 26
floralwhite 255 250 240
forestgreen 34 139 34
gainsboro 220 220 220
ghostwhite 248 248 255
gold 255 215 0
gold1 255 215 0
gold2 238 201 0
gold3 205 173 0
gold4 139 117 0
goldenrod 218 165 32
goldenrod1 255 193 37
goldenrod2 238 180 34
goldenrod3 205 155 29
goldenrod4 139 105 20
gray 190 190 190
gray0 0 0 0
gray1 3 3 3
gray2 5 5 5
gray3 8 8 8
gray4 10 10 10
gray5 13 13 13
gray6 15 15 15
gray7 18 18 18
gray8 20 20 20
gray9 23 23 23
gray10 26 26 26
gray11 28 28 28
gray12 31 31 31
gray13 33 33 33
gray14 36 36 36
gray15 38 38 38
gray16 41 41 41
gray17 43 43 43
gray18 46 46 46
gray19 48 48 48
gray20 51 51 51
gray21 54 54 54
gray22 56 56 56
gray23 59 59 59
gray24 61 61 61
gray25 64 64 64
gray26 66 66 66
gray27 69 69 69
gray28 71 71 71
gray29 74 74 74
gray30 77 77 77
gray31 79 79 79
gray32 82 82 82
gray33 84 84 84
gray34 87 87 87
gray35 89 89 89
gray36 92 92 92
gray37 94 94 94
gray38 97 97 97
gray39 99 99 99
gray40 102 102 102
gray41 105 105 105
gray42 107 107 107
gray43 110 110 110
gray44 112 112 112
gray45 115 115 115
gray46 117 117 117
gray47 120 120 120
gray48 122 122 122
gray49 125 125 125
gray50 127 127 127
gray51 130 130 130
gray52 133 133 133
gray53 135 135 135
gray54 138 138 138
gray55 140 140 140
gray56 143 143 143
gray57 145 145 145
gray58 148 148 148
gray59 150 150 150
gray60 153 153 153
gray61 156 156 156
gray62 158 158 158
gray63 161 161 161
gray64 163 163 163
gray65 166 166 166
gray66 168 168 168
gray67 171 171 171
gray68 173 173 173
gray69 176 176 176
gray70 179 179 179
gray71 181 181 181
gray72 184 184 184
gray73 186 186 186
gray74 189 189 189
gray75 191 191 191
gray76 194 194 194
gray77 196 196 196
gray78 199 199 199
gray79 201 201 201
gray80 204 204 204
gray81 207 207 207
gray82 209 209 209
gray83 212 212 212
gray84 214 214 214
gray85 217 217 217
gray86 219 219 219
gray87 222 222 222
gray88 224 224 224
gray89 227 227 227
gray90 229 229 229
gray91 232 232 232
gray92 235 235 235
gray93 237 237 237
gray94 240 240 240
gray95 242 242 242
gray96 245 245 245
gray97 247 247 247
gray98 250 250 250
gray99 252 252 252
gray100 255 255 255
green 0 255 0
green1 0 255 0
green2 0 238 0
green3 0 205 0
green4 0 139 0
greenyellow 173 255 47
grey 190 190 190
grey0 0 0 0
grey1 3 3 3
grey2 5 5 5
grey3 8 8 8
grey4 10 10 10
grey5 13 13 13
grey6 15 15 15
grey7 18 18 18
grey8 20 20 20
grey9 23 23 23
grey10 26 26 26
grey11 28 28 28
grey12 31 31 31
grey13 33 33 33
grey14 36 36 36
grey15 38 38 38
grey16 41 41 41
grey17 43 43 43
grey18 46 46 46
grey19 48 48 48
grey20 51 51 51
grey21 54 54 54
grey22 56 56 56
grey23 59 59 59
grey24 61 61 61
grey25 64 64 64
grey26 66 66 66
grey27 69 69 69
grey28 71 71 71
grey29 74 74 74
grey30 77 77 77
grey31 79 79 79
grey32 82 82 82
grey33 84 84 84
grey34 87 87 87
grey35 89 89 89
grey36 92 92 92
grey37 94 94 94
grey38 97 97 97
grey39 99 99 99
grey40 102 102 102
grey41 105 105 105
grey42 107 107 107
grey43 110 110 110
grey44 112 112 112
grey45 115 115 115
grey46 117 117 117
grey47 120 120 120
grey48 122 122 122
grey49 125 125 125
grey50 127 127 127
grey51 130 130 130
grey52 133 133 133
grey53 135 135 135
grey54 138 138 138
grey55 140 140 140
grey56 143 143 143
grey57 145 145 145
grey58 148 148 148
grey59 150 150 150
grey60 153 153 153
grey61 156 156 156
grey62 158 158 158
grey63 161 161 161
grey64 163 163 163
grey65 166 166 166
grey66 168 168 168
grey67 171 171 171
grey68 173 173 173
grey69 176 176 176
grey70 179 179 179
grey71 181 181 181
grey72 184 184 184
grey73 186 186 186
grey74 189 189 189
grey75 191 191 191
grey76 194 194 194
grey77 196 196 196
grey78 199 199 199
grey79 201 201 201
grey80 204 204 204
grey81 207 207 207
grey82 209 209 209
grey83 212 212 212
grey84 214 214 214
grey85 217 217 217
grey86 219 219 219
grey87 222 222 222
grey88 224 224 224
grey89 227 227 227
grey90 229 229 229
grey91 232 232 232
grey92 235 235 235
grey93 237 237 237
grey94 240 240 240
grey95 242 242 242
grey96 245 245 245
grey97 247 247 247
grey98 250 250 250
grey99 252 252 252
grey100 255 255 255
honeydew 240 255 240
honeydew1 240 255 240
honeydew2 224 238 224
honeydew3 193 205 193
honeydew4 131 139 131
hotpink 255 105 180
hotpink1 255 110 180
hotpink2 238 106 167
hotpink3 205 96 144
hotpink4 139 58 98
indianred 205 92 92
indianred1 255 106 106
indianred2 238 99 99
indianred3 205 85 85
indianred4 139 58 58
ivory 255 255 240
ivory1 255 255 240
ivory2 238 238 224
ivory3 205 205 193
ivory4 139 139 131
khaki 240 230 140
khaki1 255 246 143
khaki2 238 230 133
khaki3 205 198 115
khaki4 139 134 78
lavender 230 230 250
lavenderblush 255 240 245
lavenderblush1 255 240 245
lavenderblush2 238 224 229
lavenderblush3 205 193 197
lavenderblush4 139 131 134
lawngreen 124 252 0
lemonchiffon 255 250 205
lemonchiffon1 255 250 205
lemonchiffon2 238 233 191
lemonchiffon3 205 201 165
lemonchiffon4 139 137 112
lightblue 173 216 230
lightblue1 191 239 255
lightblue2 178 223 238
lightblue3 154 192 205
lightblue4 104 131 139
lightcoral 240 128 128
lightcyan 224 255 255
lightcyan1 224 255 255
lightcyan2 209 238 238
lightcyan3 180 205 205
lightcyan4 122 139 139
lightgoldenrod 238 221 130
lightgoldenrod1 255 236 139
lightgoldenrod2 238 220 130
lightgoldenrod3 205 190 112
lightgoldenrod4 139 129 76
lightgoldenrodyellow 250 250 210
lightgray 211 211 211
lightgreen 144 238 144
lightgrey 211 211 211
lightpink 255 182 193
lightpink1 255 174 185
lightpink2 238 162 173
lightpink3 205 140 149
lightpink4 139 95 101
lightsalmon 255 160 122
lightsalmon1 255 160 122
lightsalmon2 238 149 114
lightsalmon3 205 129 98
lightsalmon4 139 87 66
lightseagreen 32 178 170
lightskyblue 135 206 250
lightskyblue1 176 226 255
lightskyblue2 164 211 238
lightskyblue3 141 182 205
lightskyblue4 96 123 139
lightslateblue 132 112 255
lightslategray 119 136 153
lightslategrey 119 136 153
lightsteelblue 176 196 222
lightsteelblue1 202 225 255
lightsteelblue2 188 210 238
lightsteelblue3 162 181 205
lightsteelblue4 110 123 139
lightyellow 255 255 224
lightyellow1 255 255 224
lightyellow2 238 238 209
lightyellow3 205 205 180
lightyellow4 139 139 122
limegreen 50 205 50
linen 250 240 230
magenta 255 0 255
magenta1 255 0 255
magenta2 238 0 238
magenta3 205 0 205
magenta4 139 0 139
maroon 176 48 96
maroon1 255 52 179
maroon2 238 48 167
maroon3 205 41 144
maroon4 139 28 98
mediumaquamarine 102 205 170
mediumblue 0 0 205
mediumorchid 186 85 211
mediumorchid1 224 102 255
mediumorchid2 209 95 238
mediumorchid3 180 82 205
mediumorchid4 122 55 139
mediumpurple 147 112 219
mediumpurple1 171 130 255
mediumpurple2 159 121 238
mediumpurple3 137 104 205
mediumpurple4 93 71 139
mediumseagreen 60 179 113
mediumslateblue 123 104 238
mediumspringgreen 0 250 154
mediumturquoise 72 209 204
mediumvioletred 199 21 133
midnightblue 25 25 112
mintcream 245 255 250
mistyrose 255 228 225
mistyrose1 255 228 225
mistyrose2 238 213 210
mistyrose3 205 183 181
mistyrose4 139 125 123
moccasin 255 228 181
navajowhite 255 222 173
navajowhite1 255 222 173
navajowhite2 238 207 161
navajowhite3 205 179 139
navajowhite4 139 121 94
navy 0 0 128
navyblue 0 0 128
oldlace 253 245 230
olivedrab 107 142 35
olivedrab1 192 255 62
olivedrab2 179 238 58
olivedrab3 154 205 50
olivedrab4 105 139 34
orange 255 165 0
orange1 255 165 0
orange2 238 154 0
orange3 205 133 0
orange4 139 90 0
orangered 255 69 0
orangered1 255 69 0
orangered2 238 64 0
orangered3 205 55 0
orangered4 139 37 0
orchid 218 112 214
orchid1 255 131 250
orchid2 238 122 233
orchid3 205 105 201
orchid4 139 71 137
palegoldenrod 238 232 170
palegreen 152 251 152
palegreen1 154 255 154
palegreen2 144 238 144
palegreen3 124 205 124
palegreen4 84 139 84
paleturquoise 175 238 238
paleturquoise1 187 255 255
paleturquoise2 174 238 238
paleturquoise3 150 205 205
paleturquoise4 102 139 139
palevioletred 219 112 147
palevioletred1 255 130 171
palevioletred2 238 121 159
palevioletred3 205 104 137
palevioletred4 139 71 93
papayawhip 255 239 213
peachpuff 255 218 185
peachpuff1 255 218 185
peachpuff2 238 203 173
peachpuff3 205 175 149
peachpuff4 139 119 101
peru 205 133 63
pink 255 192 203
pink1 255 181 197
pink2 238 169 184
pink3 205 145 158
pink4 139 99 108
plum 221 160 221
plum1 255 187 255
plum2 238 174 238
plum3 205 150 205
plum4 139 102 139
powderblue 176 224 230
purple 160 32 240
purple1 155 48 255
purple2 145 44 238
purple3 125 38 205
purple4 85 26 139
red 255 0 0
red1 255 0 0
red2 238 0 0
red3 205 0 0
red4 139 0 0
rosybrown 188 143 143
rosybrown1 255 193 193
rosybrown2 238 180 180
rosybrown3 205 155 155
rosybrown4 139 105 105
royalblue 65 105 225
royalblue1 72 118 255
royalblue2 67 110 238
royalblue3 58 95 205
royalblue4 39 64 139
saddlebrown 139 69 19
salmon 250 128 114
salmon1 255 140 105
salmon2 238 130 98
salmon3 205 112 84
salmon4 139 76 57
sandybrown 244 164 96
seagreen 46 139 87
seagreen1 84 255 159
seagreen2 78 238 148
seagreen3 67 205 128
seagreen4 46 139 87
seashell 255 245 238
seashell1 255 245 238
seashell2 238 229 222
seashell3 205 197 191
seashell4 139 134 130
sienna 160 82 45
sienna1 255 130 71
sienna2 238 121 66
sienna3 205 104 57
sienna4 139 71 38
skyblue 135 206 235
skyblue1 135 206 255
skyblue2 126 192 238
skyblue3 108 166 205
skyblue4 74 112 139
slateblue 106 90 205
slateblue1 131 111 255
slateblue2 122 103 238
slateblue3 105 89 205
slateblue4 71 60 139
slategray 112 128 144
slategray1 198 226 255
slategray2 185 211 238
slategray3 159 182 205
slategray4 108 123 139
slategrey 112 128 144
snow 255 250 250
snow1 255 250 250
snow2 238 233 233
snow3 205 201 201
snow4 139 137 137
springgreen 0 255 127
springgreen1 0 255 127
springgreen2 0 238 118
springgreen3 0 205 102
springgreen4 0 139 69
steelblue 70 130 180
steelblue1 99 184 255
steelblue2 92 172 238
steelblue3 79 148 205
steelblue4 54 100 139
tan 210 180 140
tan1 255 165 79
tan2 238 154 73
tan3 205 133 63
tan4 139 90 43
thistle 216 191 216
thistle1 255 225 255
thistle2 238 210 238
thistle3 205 181 205
thistle4 139 123 139
tomato 255 99 71
tomato1 255 99 71
tomato2 238 92 66
tomato3 205 79 57
tomato4 139 54 38
turquoise 64 224 208
turquoise1 0 245 255
turquoise2 0 229 238
turquoise3 0 197 205
turquoise4 0 134 139
violet 238 130 238
violetred 208 32 144
violetred1 255 62 150
violetred2 238 58 140
violetred3 205 50 120
violetred4 139 34 82
wheat 245 222 179
wheat1 255 231 186
wheat2 238 216 174
wheat3 205 186 150
wheat4 139 126 102
whitesmoke 245 245 245
yellow 255 255 0
yellow1 255 255 0
yellow2 238 238 0
yellow3 205 205 0
yellow4 139 139 0
yellowgreen 154 205 50
>
> ccodes <- c(256^(2:0) %*% crgb) # = internal codes
> ## How many names are 'aliases' of each other:
> table(tcc <- table(ccodes))
1 2 3 4
352 146 3 1
> length(uc <- unique(sort(ccodes))) # 502
[1] 502
> ## All the multiply named colors:
> mult <- uc[tcc >= 2]
> cl <- lapply(mult, function(m) cc[ccodes == m])
> names(cl) <- apply(col2rgb(sapply(cl, function(x)x[1])),
+ 2, function(n)paste(n, collapse = ","))
> utils::str(cl)
List of 150
$ 0,0,0 : chr [1:3] "black" "gray0" "grey0"
$ 0,0,128 : chr [1:2] "navy" "navyblue"
$ 0,0,139 : chr [1:2] "blue4" "darkblue"
$ 0,0,205 : chr [1:2] "blue3" "mediumblue"
$ 0,0,255 : chr [1:2] "blue" "blue1"
$ 0,139,139 : chr [1:2] "cyan4" "darkcyan"
$ 0,191,255 : chr [1:2] "deepskyblue" "deepskyblue1"
$ 0,255,0 : chr [1:2] "green" "green1"
$ 0,255,127 : chr [1:2] "springgreen" "springgreen1"
$ 0,255,255 : chr [1:2] "cyan" "cyan1"
$ 3,3,3 : chr [1:2] "gray1" "grey1"
$ 5,5,5 : chr [1:2] "gray2" "grey2"
$ 8,8,8 : chr [1:2] "gray3" "grey3"
$ 10,10,10 : chr [1:2] "gray4" "grey4"
$ 13,13,13 : chr [1:2] "gray5" "grey5"
$ 15,15,15 : chr [1:2] "gray6" "grey6"
$ 18,18,18 : chr [1:2] "gray7" "grey7"
$ 20,20,20 : chr [1:2] "gray8" "grey8"
$ 23,23,23 : chr [1:2] "gray9" "grey9"
$ 26,26,26 : chr [1:2] "gray10" "grey10"
$ 28,28,28 : chr [1:2] "gray11" "grey11"
$ 30,144,255 : chr [1:2] "dodgerblue" "dodgerblue1"
$ 31,31,31 : chr [1:2] "gray12" "grey12"
$ 33,33,33 : chr [1:2] "gray13" "grey13"
$ 36,36,36 : chr [1:2] "gray14" "grey14"
$ 38,38,38 : chr [1:2] "gray15" "grey15"
$ 41,41,41 : chr [1:2] "gray16" "grey16"
$ 43,43,43 : chr [1:2] "gray17" "grey17"
$ 46,46,46 : chr [1:2] "gray18" "grey18"
$ 46,139,87 : chr [1:2] "seagreen" "seagreen4"
$ 47,79,79 : chr [1:2] "darkslategray" "darkslategrey"
$ 48,48,48 : chr [1:2] "gray19" "grey19"
$ 51,51,51 : chr [1:2] "gray20" "grey20"
$ 54,54,54 : chr [1:2] "gray21" "grey21"
$ 56,56,56 : chr [1:2] "gray22" "grey22"
$ 59,59,59 : chr [1:2] "gray23" "grey23"
$ 61,61,61 : chr [1:2] "gray24" "grey24"
$ 64,64,64 : chr [1:2] "gray25" "grey25"
$ 66,66,66 : chr [1:2] "gray26" "grey26"
$ 69,69,69 : chr [1:2] "gray27" "grey27"
$ 71,71,71 : chr [1:2] "gray28" "grey28"
$ 74,74,74 : chr [1:2] "gray29" "grey29"
$ 77,77,77 : chr [1:2] "gray30" "grey30"
$ 79,79,79 : chr [1:2] "gray31" "grey31"
$ 82,82,82 : chr [1:2] "gray32" "grey32"
$ 84,84,84 : chr [1:2] "gray33" "grey33"
$ 87,87,87 : chr [1:2] "gray34" "grey34"
$ 89,89,89 : chr [1:2] "gray35" "grey35"
$ 92,92,92 : chr [1:2] "gray36" "grey36"
$ 94,94,94 : chr [1:2] "gray37" "grey37"
$ 97,97,97 : chr [1:2] "gray38" "grey38"
$ 99,99,99 : chr [1:2] "gray39" "grey39"
$ 102,102,102: chr [1:2] "gray40" "grey40"
$ 102,205,170: chr [1:2] "aquamarine3" "mediumaquamarine"
$ 105,105,105: chr [1:4] "dimgray" "dimgrey" "gray41" "grey41"
$ 107,107,107: chr [1:2] "gray42" "grey42"
$ 110,110,110: chr [1:2] "gray43" "grey43"
$ 112,112,112: chr [1:2] "gray44" "grey44"
$ 112,128,144: chr [1:2] "slategray" "slategrey"
$ 115,115,115: chr [1:2] "gray45" "grey45"
$ 117,117,117: chr [1:2] "gray46" "grey46"
$ 119,136,153: chr [1:2] "lightslategray" "lightslategrey"
$ 120,120,120: chr [1:2] "gray47" "grey47"
$ 122,122,122: chr [1:2] "gray48" "grey48"
$ 125,125,125: chr [1:2] "gray49" "grey49"
$ 127,127,127: chr [1:2] "gray50" "grey50"
$ 127,255,0 : chr [1:2] "chartreuse" "chartreuse1"
$ 127,255,212: chr [1:2] "aquamarine" "aquamarine1"
$ 130,130,130: chr [1:2] "gray51" "grey51"
$ 133,133,133: chr [1:2] "gray52" "grey52"
$ 135,135,135: chr [1:2] "gray53" "grey53"
$ 138,138,138: chr [1:2] "gray54" "grey54"
$ 139,0,0 : chr [1:2] "darkred" "red4"
$ 139,0,139 : chr [1:2] "darkmagenta" "magenta4"
$ 139,69,19 : chr [1:2] "chocolate4" "saddlebrown"
$ 140,140,140: chr [1:2] "gray55" "grey55"
$ 143,143,143: chr [1:2] "gray56" "grey56"
$ 144,238,144: chr [1:2] "lightgreen" "palegreen2"
$ 145,145,145: chr [1:2] "gray57" "grey57"
$ 148,148,148: chr [1:2] "gray58" "grey58"
$ 150,150,150: chr [1:2] "gray59" "grey59"
$ 153,153,153: chr [1:2] "gray60" "grey60"
$ 154,205,50 : chr [1:2] "olivedrab3" "yellowgreen"
$ 156,156,156: chr [1:2] "gray61" "grey61"
$ 158,158,158: chr [1:2] "gray62" "grey62"
$ 161,161,161: chr [1:2] "gray63" "grey63"
$ 163,163,163: chr [1:2] "gray64" "grey64"
$ 166,166,166: chr [1:2] "gray65" "grey65"
$ 168,168,168: chr [1:2] "gray66" "grey66"
$ 169,169,169: chr [1:2] "darkgray" "darkgrey"
$ 171,171,171: chr [1:2] "gray67" "grey67"
$ 173,173,173: chr [1:2] "gray68" "grey68"
$ 176,176,176: chr [1:2] "gray69" "grey69"
$ 179,179,179: chr [1:2] "gray70" "grey70"
$ 181,181,181: chr [1:2] "gray71" "grey71"
$ 184,184,184: chr [1:2] "gray72" "grey72"
$ 186,186,186: chr [1:2] "gray73" "grey73"
$ 189,189,189: chr [1:2] "gray74" "grey74"
$ 190,190,190: chr [1:2] "gray" "grey"
[list output truncated]
> ## Not run:
> ##D if(require(xgobi)) { ## Look at the color cube dynamically :
> ##D tc <- t(crgb[, !duplicated(ccodes)])
> ##D table(is.gray <- tc[,1] == tc[,2] & tc[,2] == tc[,3]) # (397, 105)
> ##D xgobi(tc, color = c("gold", "gray")[1 + is.gray])
> ##D }
> ## End(Not run)
>
>
>
> cleanEx()
> nameEx("colorRamp")
> ### * colorRamp
>
> flush(stderr()); flush(stdout())
>
> ### Name: colorRamp
> ### Title: Color interpolation
> ### Aliases: colorRamp colorRampPalette
> ### Keywords: color
>
> ### ** Examples
>
> ## Both return a *function* :
> colorRamp(c("red", "green"))( (0:4)/4 ) ## (x) , x in [0,1]
[,1] [,2] [,3]
[1,] 255.00 0.00 0
[2,] 191.25 63.75 0
[3,] 127.50 127.50 0
[4,] 63.75 191.25 0
[5,] 0.00 255.00 0
> colorRampPalette(c("blue", "red"))( 4 ) ## (n)
[1] "#0000FF" "#5500AA" "#AA0055" "#FF0000"
> ## a ramp in opacity of blue values
> colorRampPalette(c(rgb(0,0,1,1), rgb(0,0,1,0)), alpha = TRUE)(8)
[1] "#0000FFFF" "#0000FFDA" "#0000FFB6" "#0000FF91" "#0000FF6D" "#0000FF48"
[7] "#0000FF24" "#0000FF00"
>
> require(graphics)
>
> ## Here space="rgb" gives palettes that vary only in saturation,
> ## as intended.
> ## With space="Lab" the steps are more uniform, but the hues
> ## are slightly purple.
> filled.contour(volcano,
+ color.palette =
+ colorRampPalette(c("red", "white", "blue")),
+ asp = 1)
> filled.contour(volcano,
+ color.palette =
+ colorRampPalette(c("red", "white", "blue"),
+ space = "Lab"),
+ asp = 1)
>
> ## Interpolating a 'sequential' ColorBrewer palette
> YlOrBr <- c("#FFFFD4", "#FED98E", "#FE9929", "#D95F0E", "#993404")
> filled.contour(volcano,
+ color.palette = colorRampPalette(YlOrBr, space = "Lab"),
+ asp = 1)
> filled.contour(volcano,
+ color.palette = colorRampPalette(YlOrBr, space = "Lab",
+ bias = 0.5),
+ asp = 1)
>
> ## 'jet.colors' is "as in Matlab"
> ## (and hurting the eyes by over-saturation)
> jet.colors <-
+ colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan",
+ "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
> filled.contour(volcano, color = jet.colors, asp = 1)
>
> ## space="Lab" helps when colors don't form a natural sequence
> m <- outer(1:20,1:20,function(x,y) sin(sqrt(x*y)/3))
> rgb.palette <- colorRampPalette(c("red", "orange", "blue"),
+ space = "rgb")
> Lab.palette <- colorRampPalette(c("red", "orange", "blue"),
+ space = "Lab")
> filled.contour(m, col = rgb.palette(20))
> filled.contour(m, col = Lab.palette(20))
>
>
>
> cleanEx()
> nameEx("colors")
> ### * colors
>
> flush(stderr()); flush(stdout())
>
> ### Name: colors
> ### Title: Color Names
> ### Aliases: colors colours
> ### Keywords: color dplot sysdata
>
> ### ** Examples
>
> cl <- colors()
> length(cl); cl[1:20]
[1] 657
[1] "white" "aliceblue" "antiquewhite" "antiquewhite1"
[5] "antiquewhite2" "antiquewhite3" "antiquewhite4" "aquamarine"
[9] "aquamarine1" "aquamarine2" "aquamarine3" "aquamarine4"
[13] "azure" "azure1" "azure2" "azure3"
[17] "azure4" "beige" "bisque" "bisque1"
>
> length(cl. <- colors(TRUE))
[1] 502
> ## only 502 of the 657 named ones
>
> ## ----------- Show all named colors and more:
> demo("colors")
demo(colors)
---- ~~~~~~
> ### ----------- Show (almost) all named colors ---------------------
>
> ## 1) with traditional 'graphics' package:
> showCols1 <- function(bg = "gray", cex = 0.75, srt = 30) {
+ m <- ceiling(sqrt(n <- length(cl <- colors())))
+ length(cl) <- m*m; cm <- matrix(cl, m)
+ ##
+ require("graphics")
+ op <- par(mar=rep(0,4), ann=FALSE, bg = bg); on.exit(par(op))
+ plot(1:m,1:m, type="n", axes=FALSE)
+ text(col(cm), rev(row(cm)), cm, col = cl, cex=cex, srt=srt)
+ }
> showCols1()
> ## 2) with 'grid' package:
> showCols2 <- function(bg = "grey", cex = 0.75, rot = 30) {
+ m <- ceiling(sqrt(n <- length(cl <- colors())))
+ length(cl) <- m*m; cm <- matrix(cl, m)
+ ##
+ require("grid")
+ grid.newpage(); vp <- viewport(w = .92, h = .92)
+ grid.rect(gp=gpar(fill=bg))
+ grid.text(cm, x = col(cm)/m, y = rev(row(cm))/m, rot = rot,
+ vp=vp, gp=gpar(cex = cex, col = cm))
+ }
> showCols2()
Loading required package: grid
> showCols2(bg = "gray33")
> ###
>
> ##' @title Comparing Colors
> ##' @param col
> ##' @param nrow
> ##' @param ncol
> ##' @param txt.col
> ##' @return the grid layout, invisibly
> ##' @author Marius Hofert, originally
> plotCol <- function(col, nrow=1, ncol=ceiling(length(col) / nrow),
+ txt.col="black") {
+ stopifnot(nrow >= 1, ncol >= 1)
+ if(length(col) > nrow*ncol)
+ warning("some colors will not be shown")
+ require(grid)
+ grid.newpage()
+ gl <- grid.layout(nrow, ncol)
+ pushViewport(viewport(layout=gl))
+ ic <- 1
+ for(i in 1:nrow) {
+ for(j in 1:ncol) {
+ pushViewport(viewport(layout.pos.row=i, layout.pos.col=j))
+ grid.rect(gp= gpar(fill=col[ic]))
+ grid.text(col[ic], gp=gpar(col=txt.col))
+ upViewport()
+ ic <- ic+1
+ }
+ }
+ upViewport()
+ invisible(gl)
+ }
> ## A Chocolate Bar of colors:
> plotCol(c("#CC8C3C", paste0("chocolate", 2:4),
+ paste0("darkorange", c("",1:2)), paste0("darkgoldenrod", 1:2),
+ "orange", "orange1", "sandybrown", "tan1", "tan2"),
+ nrow=2)
> ##' Find close R colors() to a given color {original by Marius Hofert)
> ##' using Euclidean norm in (HSV / RGB / ...) color space
> nearRcolor <- function(rgb, cSpace = c("hsv", "rgb255", "Luv", "Lab"),
+ dist = switch(cSpace, "hsv" = 0.10, "rgb255" = 30,
+ "Luv" = 15, "Lab" = 12))
+ {
+ if(is.character(rgb)) rgb <- col2rgb(rgb)
+ stopifnot(length(rgb <- as.vector(rgb)) == 3)
+ Rcol <- col2rgb(.cc <- colors())
+ uniqC <- !duplicated(t(Rcol)) # gray9 == grey9 (etc)
+ Rcol <- Rcol[, uniqC] ; .cc <- .cc[uniqC]
+ cSpace <- match.arg(cSpace)
+ convRGB2 <- function(Rgb, to)
+ t(convertColor(t(Rgb), from="sRGB", to=to, scale.in=255))
+ ## the transformation, rgb{0..255} --> cSpace :
+ TransF <- switch(cSpace,
+ "rgb255" = identity,
+ "hsv" = rgb2hsv,
+ "Luv" = function(RGB) convRGB2(RGB, "Luv"),
+ "Lab" = function(RGB) convRGB2(RGB, "Lab"))
+ d <- sqrt(colSums((TransF(Rcol) - as.vector(TransF(rgb)))^2))
+ iS <- sort.list(d[near <- d <= dist])# sorted: closest first
+ setNames(.cc[near][iS], format(d[near][iS], digits=3))
+ }
> nearRcolor(col2rgb("tan2"), "rgb")
0.0 21.1 25.8 29.5
"tan2" "tan1" "sandybrown" "sienna1"
> nearRcolor(col2rgb("tan2"), "hsv")
0.0000 0.0410 0.0618 0.0638 0.0667 0.0766
"tan2" "sienna2" "coral2" "tomato2" "tan1" "coral"
0.0778 0.0900 0.0912 0.0918
"sienna1" "sandybrown" "coral1" "tomato"
> nearRcolor(col2rgb("tan2"), "Luv")
0.00 7.42 7.48 12.41 13.69
"tan2" "tan1" "sandybrown" "orange3" "orange2"
> nearRcolor(col2rgb("tan2"), "Lab")
0.00 5.56 8.08 11.31
"tan2" "tan1" "sandybrown" "peru"
> nearRcolor("#334455")
0.0867
"darkslategray"
> ## Now, consider choosing a color by looking in the
> ## neighborhood of one you know :
>
> plotCol(nearRcolor("deepskyblue", "rgb", dist=50))
> plotCol(nearRcolor("deepskyblue", dist=.1))
> plotCol(nearRcolor("tomato", "rgb", dist= 50), nrow=3)
> plotCol(nearRcolor("tomato", "hsv", dist=.12), nrow=3)
> plotCol(nearRcolor("tomato", "Luv", dist= 25), nrow=3)
> plotCol(nearRcolor("tomato", "Lab", dist= 18), nrow=3)
> ## -----------
>
>
>
> cleanEx()
detaching ‘package:grid’
> nameEx("contourLines")
> ### * contourLines
>
> flush(stderr()); flush(stdout())
>
> ### Name: contourLines
> ### Title: Calculate Contour Lines
> ### Aliases: contourLines
> ### Keywords: dplot
>
> ### ** Examples
>
> x <- 10*1:nrow(volcano)
> y <- 10*1:ncol(volcano)
> contourLines(x, y, volcano)
>
>
>
> cleanEx()
> nameEx("convertColor")
> ### * convertColor
>
> flush(stderr()); flush(stdout())
>
> ### Name: convertColor
> ### Title: Convert between Colour Spaces
> ### Aliases: convertColor colorspaces
> ### Keywords: color
>
> ### ** Examples
>
> ## The displayable colors from four planes of Lab space
> ab <- expand.grid(a = (-10:15)*10,
+ b = (-15:10)*10)
> require(graphics); require(stats) # for na.omit
> par(mfrow = c(2, 2), mar = .1+c(3, 3, 3, .5), mgp = c(2, .8, 0))
>
> Lab <- cbind(L = 20, ab)
> srgb <- convertColor(Lab, from = "Lab", to = "sRGB", clip = NA)
> clipped <- attr(na.omit(srgb), "na.action")
> srgb[clipped, ] <- 0
> cols <- rgb(srgb[, 1], srgb[, 2], srgb[, 3])
> image((-10:15)*10, (-15:10)*10, matrix(1:(26*26), ncol = 26), col = cols,
+ xlab = "a", ylab = "b", main = "Lab: L=20")
>
> Lab <- cbind(L = 40, ab)
> srgb <- convertColor(Lab, from = "Lab", to = "sRGB", clip = NA)
> clipped <- attr(na.omit(srgb), "na.action")
> srgb[clipped, ] <- 0
> cols <- rgb(srgb[, 1], srgb[, 2], srgb[, 3])
> image((-10:15)*10, (-15:10)*10, matrix(1:(26*26), ncol = 26), col = cols,
+ xlab = "a", ylab = "b", main = "Lab: L=40")
>
> Lab <- cbind(L = 60, ab)
> srgb <- convertColor(Lab, from = "Lab", to = "sRGB", clip = NA)
> clipped <- attr(na.omit(srgb), "na.action")
> srgb[clipped, ] <- 0
> cols <- rgb(srgb[, 1], srgb[, 2], srgb[, 3])
> image((-10:15)*10, (-15:10)*10, matrix(1:(26*26), ncol = 26), col = cols,
+ xlab = "a", ylab = "b", main = "Lab: L=60")
>
> Lab <- cbind(L = 80, ab)
> srgb <- convertColor(Lab, from = "Lab", to = "sRGB", clip = NA)
> clipped <- attr(na.omit(srgb), "na.action")
> srgb[clipped, ] <- 0
> cols <- rgb(srgb[, 1], srgb[, 2], srgb[, 3])
> image((-10:15)*10, (-15:10)*10, matrix(1:(26*26), ncol = 26), col = cols,
+ xlab = "a", ylab = "b", main = "Lab: L=80")
>
> cols <- t(col2rgb(palette())); rownames(cols) <- palette(); cols
red green blue
black 0 0 0
red 255 0 0
green3 0 205 0
blue 0 0 255
cyan 0 255 255
magenta 255 0 255
yellow 255 255 0
gray 190 190 190
> zapsmall(lab <- convertColor(cols, from = "sRGB", to = "Lab", scale.in = 255))
L a.x b
black 0.00000 0.00000 0.00000
red 53.48418 80.01027 67.38407
green3 71.91841 -73.33548 70.41134
blue 32.24075 78.82042 -107.93632
cyan 91.01106 -48.46075 -14.29081
magenta 60.50231 97.95195 -60.51490
yellow 97.14950 -21.36677 94.42044
gray 76.97594 0.00000 0.00000
> stopifnot(all.equal(cols, # converting back.. getting the original:
+ round(convertColor(lab, from = "Lab", to = "sRGB", scale.out = 255)),
+ check.attributes = FALSE))
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("densCols")
> ### * densCols
>
> flush(stderr()); flush(stdout())
>
> ### Name: densCols
> ### Title: Colors for Smooth Density Plots
> ### Aliases: densCols blues9
> ### Keywords: dplot
>
> ### ** Examples
>
>
> cleanEx()
> nameEx("dev")
> ### * dev
>
> flush(stderr()); flush(stdout())
>
> ### Name: dev
> ### Title: Control Multiple Devices
> ### Aliases: dev.cur dev.list dev.next dev.prev dev.off dev.set dev.new
> ### graphics.off
> ### Keywords: device iplot
>
> ### ** Examples
>
> ## Not run:
> ##D ## Unix-specific example
> ##D x11()
> ##D plot(1:10)
> ##D x11()
> ##D plot(rnorm(10))
> ##D dev.set(dev.prev())
> ##D abline(0, 1) # through the 1:10 points
> ##D dev.set(dev.next())
> ##D abline(h = 0, col = "gray") # for the residual plot
> ##D dev.set(dev.prev())
> ##D dev.off(); dev.off() #- close the two X devices
> ## End(Not run)
>
>
>
> cleanEx()
> nameEx("dev.capabilities")
> ### * dev.capabilities
>
> flush(stderr()); flush(stdout())
>
> ### Name: dev.capabilities
> ### Title: Query Capabilities of the Current Graphics Device
> ### Aliases: dev.capabilities
> ### Keywords: dplot
>
> ### ** Examples
>
> dev.capabilities()
$semiTransparency
[1] TRUE
$transparentBackground
[1] "semi"
$rasterImage
[1] "yes"
$capture
[1] FALSE
$locator
[1] FALSE
$events
character(0)
>
>
>
> cleanEx()
> nameEx("dev.interactive")
> ### * dev.interactive
>
> flush(stderr()); flush(stdout())
>
> ### Name: dev.interactive
> ### Title: Is the Current Graphics Device Interactive?
> ### Aliases: dev.interactive deviceIsInteractive
> ### Keywords: device
>
> ### ** Examples
>
> dev.interactive()
[1] FALSE
> print(deviceIsInteractive(NULL))
[1] "X11" "X11cairo" "quartz" "windows" "JavaGD" "CairoWin" "CairoX11"
>
>
>
> cleanEx()
> nameEx("dev.size")
> ### * dev.size
>
> flush(stderr()); flush(stdout())
>
> ### Name: dev.size
> ### Title: Find Size of Device Surface
> ### Aliases: dev.size
> ### Keywords: dplot
>
> ### ** Examples
>
> dev.size("cm")
[1] 17.78 17.78
>
>
>
> cleanEx()
> nameEx("dev2")
> ### * dev2
>
> flush(stderr()); flush(stdout())
>
> ### Name: dev2
> ### Title: Copy Graphics Between Multiple Devices
> ### Aliases: dev.copy dev.print dev.copy2eps dev.copy2pdf dev.control
> ### Keywords: device
>
> ### ** Examples
>
> ## Not run:
> ##D x11() # on a Unix-alike
> ##D plot(rnorm(10), main = "Plot 1")
> ##D dev.copy(device = x11)
> ##D mtext("Copy 1", 3)
> ##D dev.print(width = 6, height = 6, horizontal = FALSE) # prints it
> ##D dev.off(dev.prev())
> ##D dev.off()
> ## End(Not run)
>
>
>
> cleanEx()
> nameEx("extendrange")
> ### * extendrange
>
> flush(stderr()); flush(stdout())
>
> ### Name: extendrange
> ### Title: Extend a Numerical Range by a Small Percentage
> ### Aliases: extendrange
> ### Keywords: dplot
>
> ### ** Examples
>
> x <- 1:5
> (r <- range(x)) # 1 5
[1] 1 5
> extendrange(x) # 0.8 5.2
[1] 0.8 5.2
> extendrange(x, f= 0.01) # 0.96 5.04
[1] 0.96 5.04
> ## Use 'r' if you have it already:
> stopifnot(identical(extendrange(r = r),
+ extendrange(x)))
>
>
>
> cleanEx()
> nameEx("getGraphicsEvent")
> ### * getGraphicsEvent
>
> flush(stderr()); flush(stdout())
>
> ### Name: getGraphicsEvent
> ### Title: Wait for a mouse or keyboard event from a graphics window
> ### Aliases: getGraphicsEvent setGraphicsEventHandlers getGraphicsEventEnv
> ### setGraphicsEventEnv
> ### Keywords: iplot
>
> ### ** Examples
>
> # This currently only works on the Windows
> # and X11(type = "Xlib") screen devices...
> ## Not run:
> ##D savepar <- par(ask = FALSE)
> ##D dragplot <- function(..., xlim = NULL, ylim = NULL, xaxs = "r", yaxs = "r") {
> ##D plot(..., xlim = xlim, ylim = ylim, xaxs = xaxs, yaxs = yaxs)
> ##D startx <- NULL
> ##D starty <- NULL
> ##D prevx <- NULL
> ##D prevy <- NULL
> ##D usr <- NULL
> ##D
> ##D devset <- function()
> ##D if (dev.cur() != eventEnv$which) dev.set(eventEnv$which)
> ##D
> ##D dragmousedown <- function(buttons, x, y) {
> ##D startx <<- x
> ##D starty <<- y
> ##D prevx <<- 0
> ##D prevy <<- 0
> ##D devset()
> ##D usr <<- par("usr")
> ##D eventEnv$onMouseMove <- dragmousemove
> ##D NULL
> ##D }
> ##D
> ##D dragmousemove <- function(buttons, x, y) {
> ##D devset()
> ##D deltax <- diff(grconvertX(c(startx, x), "ndc", "user"))
> ##D deltay <- diff(grconvertY(c(starty, y), "ndc", "user"))
> ##D if (abs(deltax-prevx) + abs(deltay-prevy) > 0) {
> ##D plot(..., xlim = usr[1:2]-deltax, xaxs = "i",
> ##D ylim = usr[3:4]-deltay, yaxs = "i")
> ##D prevx <<- deltax
> ##D prevy <<- deltay
> ##D }
> ##D NULL
> ##D }
> ##D
> ##D mouseup <- function(buttons, x, y) {
> ##D eventEnv$onMouseMove <- NULL
> ##D }
> ##D
> ##D keydown <- function(key) {
> ##D if (key == "q") return(invisible(1))
> ##D eventEnv$onMouseMove <- NULL
> ##D NULL
> ##D }
> ##D
> ##D setGraphicsEventHandlers(prompt = "Click and drag, hit q to quit",
> ##D onMouseDown = dragmousedown,
> ##D onMouseUp = mouseup,
> ##D onKeybd = keydown)
> ##D eventEnv <- getGraphicsEventEnv()
> ##D }
> ##D
> ##D dragplot(rnorm(1000), rnorm(1000))
> ##D getGraphicsEvent()
> ##D par(savepar)
> ## End(Not run)
>
>
>
> cleanEx()
> nameEx("gray")
> ### * gray
>
> flush(stderr()); flush(stdout())
>
> ### Name: gray
> ### Title: Gray Level Specification
> ### Aliases: gray grey
> ### Keywords: color
>
> ### ** Examples
>
> gray(0:8 / 8)
[1] "#000000" "#202020" "#404040" "#606060" "#808080" "#9F9F9F" "#BFBFBF"
[8] "#DFDFDF" "#FFFFFF"
>
>
>
> cleanEx()
> nameEx("gray.colors")
> ### * gray.colors
>
> flush(stderr()); flush(stdout())
>
> ### Name: gray.colors
> ### Title: Gray Color Palette
> ### Aliases: gray.colors grey.colors
> ### Keywords: color
>
> ### ** Examples
>
> require(graphics)
>
> pie(rep(1, 12), col = gray.colors(12))
> barplot(1:12, col = gray.colors(12))
>
>
>
> cleanEx()
> nameEx("hcl")
> ### * hcl
>
> flush(stderr()); flush(stdout())
>
> ### Name: hcl
> ### Title: HCL Color Specification
> ### Aliases: hcl
> ### Keywords: color dplot
>
> ### ** Examples
>
> require(graphics)
>
> # The Foley and Van Dam PhD Data.
> csd <- matrix(c( 4,2,4,6, 4,3,1,4, 4,7,7,1,
+ 0,7,3,2, 4,5,3,2, 5,4,2,2,
+ 3,1,3,0, 4,4,6,7, 1,10,8,7,
+ 1,5,3,2, 1,5,2,1, 4,1,4,3,
+ 0,3,0,6, 2,1,5,5), nrow = 4)
>
> csphd <- function(colors)
+ barplot(csd, col = colors, ylim = c(0,30),
+ names = 72:85, xlab = "Year", ylab = "Students",
+ legend = c("Winter", "Spring", "Summer", "Fall"),
+ main = "Computer Science PhD Graduates", las = 1)
>
> # The Original (Metaphorical) Colors (Ouch!)
> csphd(c("blue", "green", "yellow", "orange"))
>
> # A Color Tetrad (Maximal Color Differences)
> csphd(hcl(h = c(30, 120, 210, 300)))
>
> # Same, but lighter and less colorful
> # Turn off automatic correction to make sure
> # that we have defined real colors.
> csphd(hcl(h = c(30, 120, 210, 300),
+ c = 20, l = 90, fixup = FALSE))
>
> # Analogous Colors
> # Good for those with red/green color confusion
> csphd(hcl(h = seq(60, 240, by = 60)))
>
> # Metaphorical Colors
> csphd(hcl(h = seq(210, 60, length = 4)))
>
> # Cool Colors
> csphd(hcl(h = seq(120, 0, length = 4) + 150))
>
> # Warm Colors
> csphd(hcl(h = seq(120, 0, length = 4) - 30))
>
> # Single Color
> hist(stats::rnorm(1000), col = hcl(240))
>
> ## Exploring the hcl() color space {in its mapping to R's sRGB colors}:
> demo(hclColors)
demo(hclColors)
---- ~~~~~~~~~
> ### ------ hcl() explorations
>
> hcl.wheel <-
+ function(chroma = 35, lums = 0:100, hues = 1:360, asp = 1,
+ p.cex = 0.6, do.label = FALSE, rev.lum = FALSE,
+ fixup = TRUE)
+ {
+ ## Purpose: show chroma "sections" of hcl() color space; see ?hcl
+ ## ----------------------------------------------------------------------
+ ## Arguments: chroma: can be vector -> multiple plots are done,
+ ## lums, hues, fixup : all corresponding to hcl()'s args
+ ## rev.lum: logical indicating if luminance
+ ## should go from outer to inner
+ ## ----------------------------------------------------------------------
+ ## Author: Martin Maechler, Date: 24 Jun 2005
+
+ require("graphics")
+ stopifnot(is.numeric(lums), lums >= 0, lums <= 100,
+ is.numeric(hues), hues >= 0, hues <= 360,
+ is.numeric(chroma), chroma >= 0, (nch <- length(chroma)) >= 1)
+ if(is.unsorted(hues)) hues <- sort(hues)
+ if(nch > 1) {
+ op <- par(mfrow= n2mfrow(nch), mar = c(0,0,0,0), xpd = TRUE)
+ on.exit(par(op))
+ }
+ for(i.c in 1:nch) {
+ plot(-1:1,-1:1, type="n", axes = FALSE, xlab="",ylab="", asp = asp)
+ ## main = sprintf("hcl(h = <angle>, c = %g)", chroma[i.c]),
+ text(0.4, 0.99, paste("chroma =", format(chroma[i.c])),
+ adj = 0, font = 4)
+ l.s <- (if(rev.lum) rev(lums) else lums) / max(lums) # <= 1
+ for(ang in hues) { # could do all this using outer() instead of for()...
+ a. <- ang * pi/180
+ z.a <- exp(1i * a.)
+ cols <- hcl(ang, c = chroma[i.c], l = lums, fixup = fixup)
+ points(l.s * z.a, pch = 16, col = cols, cex = p.cex)
+ ##if(do."text") : draw the 0,45,90,... angle "lines"
+ if(do.label)
+ text(z.a*1.05, labels = ang, col = cols[length(cols)/2],
+ srt = ang)
+ }
+ if(!fixup) ## show the outline
+ lines(exp(1i * hues * pi/180))
+ }
+ invisible()
+ }
> ## and now a few interesting calls :
>
> hcl.wheel() # and watch it redraw when you fiddle with the graphic window
> hcl.wheel(rev.lum= TRUE) # ditto
> hcl.wheel(do.lab = TRUE) # ditto
> ## Now watch:
> hcl.wheel(ch = c(25,35,45,55))
> hcl.wheel(ch = seq(10, 90, by = 10), p.cex = 0.4)
> hcl.wheel(ch = seq(10, 90, by = 10), p.cex = 0.3, fixup = FALSE)
> hcl.wheel(ch = seq(10, 90, by = 10), p.cex = 0.3, rev.lum = TRUE)
> if(dev.interactive()) # new "graphics window" -- to compare with previous :
+ dev.new()
> hcl.wheel(ch = seq(10, 90, by = 10), p.cex = 0.3, rev.lum = TRUE, fixup=FALSE)
>
>
>
>
> cleanEx()
> nameEx("hsv")
> ### * hsv
>
> flush(stderr()); flush(stdout())
>
> ### Name: hsv
> ### Title: HSV Color Specification
> ### Aliases: hsv
> ### Keywords: color dplot
>
> ### ** Examples
>
> require(graphics)
>
> hsv(.5,.5,.5)
[1] "#408080"
>
> ## Red tones:
> n <- 20; y <- -sin(3*pi*((1:n)-1/2)/n)
> op <- par(mar = rep(1.5, 4))
> plot(y, axes = FALSE, frame.plot = TRUE,
+ xlab = "", ylab = "", pch = 21, cex = 30,
+ bg = rainbow(n, start = .85, end = .1),
+ main = "Red tones")
> par(op)
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("make.rgb")
> ### * make.rgb
>
> flush(stderr()); flush(stdout())
>
> ### Name: make.rgb
> ### Title: Create colour spaces
> ### Aliases: make.rgb colorConverter
> ### Keywords: color
>
> ### ** Examples
>
> (pal <- make.rgb(red = c(0.6400, 0.3300),
+ green = c(0.2900, 0.6000),
+ blue = c(0.1500, 0.0600),
+ name = "PAL/SECAM RGB"))
Color space converter: PAL/SECAM RGB
Reference white: D65
display gamma = 2.2
>
> ## converter for sRGB in #rrggbb format
> hexcolor <- colorConverter(toXYZ = function(hex, ...) {
+ rgb <- t(col2rgb(hex))/255
+ colorspaces$sRGB$toXYZ(rgb, ...) },
+ fromXYZ = function(xyz, ...) {
+ rgb <- colorspaces$sRGB$fromXYZ(xyz, ..)
+ rgb <- round(rgb, 5)
+ if (min(rgb) < 0 || max(rgb) > 1)
+ as.character(NA)
+ else rgb(rgb[1], rgb[2], rgb[3])},
+ white = "D65", name = "#rrggbb")
>
> (cols <- t(col2rgb(palette())))
red green blue
[1,] 0 0 0
[2,] 255 0 0
[3,] 0 205 0
[4,] 0 0 255
[5,] 0 255 255
[6,] 255 0 255
[7,] 255 255 0
[8,] 190 190 190
> zapsmall(luv <- convertColor(cols, from = "sRGB", to = "Luv", scale.in = 255))
L u v
[1,] 0.00000 0.00000 0.00000
[2,] 53.48418 175.36468 37.80017
[3,] 71.91841 -68.70661 87.86408
[4,] 32.24075 -9.66060 -130.19297
[5,] 91.01106 -71.17303 -15.34147
[6,] 60.50231 84.56678 -108.14654
[7,] 97.14950 7.89815 106.44098
[8,] 76.97594 0.00000 0.00000
> (hex <- convertColor(luv, from = "Luv", to = hexcolor, scale.out = NULL))
[1] "#000000" "#FF0000" "#00CD00" "#0000FF" "#00FFFF" "#FF00FF" "#FFFF00"
[8] "#BEBEBE"
>
> ## must make hex a matrix before using it
> (cc <- round(convertColor(as.matrix(hex), from = hexcolor, to = "sRGB",
+ scale.in = NULL, scale.out = 255)))
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 255 0 0
[3,] 0 205 0
[4,] 0 0 255
[5,] 0 255 255
[6,] 255 0 255
[7,] 255 255 0
[8,] 190 190 190
> stopifnot(cc == cols)
>
>
>
> cleanEx()
> nameEx("n2mfrow")
> ### * n2mfrow
>
> flush(stderr()); flush(stdout())
>
> ### Name: n2mfrow
> ### Title: Compute Default mfrow From Number of Plots
> ### Aliases: n2mfrow
> ### Keywords: dplot utilities
>
> ### ** Examples
>
> require(graphics)
>
> n2mfrow(8) # 3 x 3
[1] 3 3
>
> n <- 5 ; x <- seq(-2, 2, len = 51)
> ## suppose now that 'n' is not known {inside function}
> op <- par(mfrow = n2mfrow(n))
> for (j in 1:n)
+ plot(x, x^j, main = substitute(x^ exp, list(exp = j)), type = "l",
+ col = "blue")
>
> sapply(1:10, n2mfrow)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 2 3 2 3 3 3 3 3 4
[2,] 1 1 1 2 2 2 3 3 3 3
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("nclass")
> ### * nclass
>
> flush(stderr()); flush(stdout())
>
> ### Name: nclass
> ### Title: Compute the Number of Classes for a Histogram
> ### Aliases: nclass.Sturges nclass.scott nclass.FD
> ### Keywords: univar
>
> ### ** Examples
>
> set.seed(1)
> x <- stats::rnorm(1111)
> nclass.Sturges(x)
[1] 12
>
> ## Compare them:
> NC <- function(x) c(Sturges = nclass.Sturges(x),
+ Scott = nclass.scott(x), FD = nclass.FD(x))
> NC(x)
Sturges Scott FD
12 20 26
> onePt <- rep(1, 11)
> NC(onePt) # no longer gives NaN
Sturges Scott FD
5 1 1
>
>
>
> cleanEx()
> nameEx("palette")
> ### * palette
>
> flush(stderr()); flush(stdout())
>
> ### Name: palette
> ### Title: Set or View the Graphics Palette
> ### Aliases: palette
> ### Keywords: color sysdata
>
> ### ** Examples
>
> require(graphics)
>
> palette() # obtain the current palette
[1] "black" "red" "green3" "blue" "cyan" "magenta" "yellow"
[8] "gray"
> palette(rainbow(6)) # six color rainbow
>
> (palette(gray(seq(0,.9,len = 25)))) # gray scales; print old palette
[1] "red" "yellow" "green" "cyan" "blue" "magenta"
> matplot(outer(1:100, 1:30), type = "l", lty = 1,lwd = 2, col = 1:30,
+ main = "Gray Scales Palette",
+ sub = "palette(gray(seq(0, .9, len=25)))")
> palette("default") # reset back to the default
>
> ## on a device where alpha-transparency is supported,
> ## use 'alpha = 0.3' transparency with the default palette :
> mycols <- adjustcolor(palette(), alpha.f = 0.3)
> opal <- palette(mycols)
> x <- rnorm(1000); xy <- cbind(x, 3*x + rnorm(1000))
> plot (xy, lwd = 2,
+ main = "Alpha-Transparency Palette\n alpha = 0.3")
> xy[,1] <- -xy[,1]
> points(xy, col = 8, pch = 16, cex = 1.5)
> palette("default")
>
>
>
> cleanEx()
> nameEx("palettes")
> ### * palettes
>
> flush(stderr()); flush(stdout())
>
> ### Name: Palettes
> ### Title: Color Palettes
> ### Aliases: rainbow heat.colors terrain.colors topo.colors cm.colors
> ### Keywords: color dplot
>
> ### ** Examples
>
> require(graphics)
> # A Color Wheel
> pie(rep(1, 12), col = rainbow(12))
>
> ##------ Some palettes ------------
> demo.pal <-
+ function(n, border = if (n < 32) "light gray" else NA,
+ main = paste("color palettes; n=", n),
+ ch.col = c("rainbow(n, start=.7, end=.1)", "heat.colors(n)",
+ "terrain.colors(n)", "topo.colors(n)",
+ "cm.colors(n)"))
+ {
+ nt <- length(ch.col)
+ i <- 1:n; j <- n / nt; d <- j/6; dy <- 2*d
+ plot(i, i+d, type = "n", yaxt = "n", ylab = "", main = main)
+ for (k in 1:nt) {
+ rect(i-.5, (k-1)*j+ dy, i+.4, k*j,
+ col = eval(parse(text = ch.col[k])), border = border)
+ text(2*j, k * j + dy/4, ch.col[k])
+ }
+ }
> n <- if(.Device == "postscript") 64 else 16
> # Since for screen, larger n may give color allocation problem
> demo.pal(n)
>
>
>
> cleanEx()
> nameEx("pdf")
> ### * pdf
>
> flush(stderr()); flush(stdout())
>
> ### Name: pdf
> ### Title: PDF Graphics Device
> ### Aliases: pdf
> ### Keywords: device
>
> ### ** Examples
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("pdf.options")
> ### * pdf.options
>
> flush(stderr()); flush(stdout())
>
> ### Name: pdf.options
> ### Title: Auxiliary Function to Set/View Defaults for Arguments of pdf
> ### Aliases: pdf.options
> ### Keywords: device
>
> ### ** Examples
>
> pdf.options(bg = "pink")
> utils::str(pdf.options())
List of 18
$ width : num 7
$ height : num 7
$ onefile : logi TRUE
$ family : chr "Helvetica"
$ title : chr "R Graphics Output"
$ fonts : NULL
$ version : chr "1.4"
$ paper : chr "special"
$ encoding : chr "default"
$ bg : chr "pink"
$ fg : chr "black"
$ pointsize : num 12
$ pagecentre : logi TRUE
$ colormodel : chr "srgb"
$ useDingbats: logi TRUE
$ useKerning : logi TRUE
$ fillOddEven: logi FALSE
$ compress : logi TRUE
> pdf.options(reset = TRUE) # back to factory-fresh
>
>
>
> cleanEx()
> nameEx("pictex")
> ### * pictex
>
> flush(stderr()); flush(stdout())
>
> ### Name: pictex
> ### Title: A PicTeX Graphics Driver
> ### Aliases: pictex
> ### Keywords: device
>
> ### ** Examples
>
> require(graphics)
>
> pictex()
> plot(1:11, (-5:5)^2, type = "b", main = "Simple Example Plot")
> dev.off()
pdf
2
> ##--------------------
> ## Not run:
> ##D %% LaTeX Example
> ##D \documentclass{article}
> ##D \usepackage{pictex}
> ##D \usepackage{graphics} % for \rotatebox
> ##D \begin{document}
> ##D %...
> ##D \begin{figure}[h]
> ##D \centerline{\input{Rplots.tex}}
> ##D \caption{}
> ##D \end{figure}
> ##D %...
> ##D \end{document}
> ## End(Not run)
> ##--------------------
> unlink("Rplots.tex")
>
>
>
> cleanEx()
> nameEx("plotmath")
> ### * plotmath
>
> flush(stderr()); flush(stdout())
>
> ### Name: plotmath
> ### Title: Mathematical Annotation in R
> ### Aliases: plotmath symbol plain bold italic bolditalic hat bar dot ring
> ### widehat widetilde displaystyle textstyle scriptstyle
> ### scriptscriptstyle underline phantom over frac atop integral inf sup
> ### group bgroup
> ### Keywords: aplot
>
> ### ** Examples
>
> require(graphics)
>
> x <- seq(-4, 4, len = 101)
> y <- cbind(sin(x), cos(x))
> matplot(x, y, type = "l", xaxt = "n",
+ main = expression(paste(plain(sin) * phi, " and ",
+ plain(cos) * phi)),
+ ylab = expression("sin" * phi, "cos" * phi), # only 1st is taken
+ xlab = expression(paste("Phase Angle ", phi)),
+ col.main = "blue")
> axis(1, at = c(-pi, -pi/2, 0, pi/2, pi),
+ labels = expression(-pi, -pi/2, 0, pi/2, pi))
>
>
> ## How to combine "math" and numeric variables :
> plot(1:10, type="n", xlab="", ylab="", main = "plot math & numbers")
> theta <- 1.23 ; mtext(bquote(hat(theta) == .(theta)), line= .25)
> for(i in 2:9)
+ text(i, i+1, substitute(list(xi, eta) == group("(",list(x,y),")"),
+ list(x = i, y = i+1)))
> ## note that both of these use calls rather than expressions.
> ##
> text(1, 10, "Derivatives:", adj = 0)
> text(1, 9.6, expression(
+ " first: {f * minute}(x) " == {f * minute}(x)), adj = 0)
> text(1, 9.0, expression(
+ " second: {f * second}(x) " == {f * second}(x)), adj = 0)
>
>
> plot(1:10, 1:10)
> text(4, 9, expression(hat(beta) == (X^t * X)^{-1} * X^t * y))
> text(4, 8.4, "expression(hat(beta) == (X^t * X)^{-1} * X^t * y)",
+ cex = .8)
> text(4, 7, expression(bar(x) == sum(frac(x[i], n), i==1, n)))
> text(4, 6.4, "expression(bar(x) == sum(frac(x[i], n), i==1, n))",
+ cex = .8)
> text(8, 5, expression(paste(frac(1, sigma*sqrt(2*pi)), " ",
+ plain(e)^{frac(-(x-mu)^2, 2*sigma^2)})),
+ cex = 1.2)
>
> ## some other useful symbols
> plot.new(); plot.window(c(0,4), c(15,1))
> text(1, 1, "universal", adj = 0); text(2.5, 1, "\\042")
> text(3, 1, expression(symbol("\042")))
> text(1, 2, "existential", adj = 0); text(2.5, 2, "\\044")
> text(3, 2, expression(symbol("\044")))
> text(1, 3, "suchthat", adj = 0); text(2.5, 3, "\\047")
> text(3, 3, expression(symbol("\047")))
> text(1, 4, "therefore", adj = 0); text(2.5, 4, "\\134")
> text(3, 4, expression(symbol("\134")))
> text(1, 5, "perpendicular", adj = 0); text(2.5, 5, "\\136")
> text(3, 5, expression(symbol("\136")))
> text(1, 6, "circlemultiply", adj = 0); text(2.5, 6, "\\304")
> text(3, 6, expression(symbol("\304")))
> text(1, 7, "circleplus", adj = 0); text(2.5, 7, "\\305")
> text(3, 7, expression(symbol("\305")))
> text(1, 8, "emptyset", adj = 0); text(2.5, 8, "\\306")
> text(3, 8, expression(symbol("\306")))
> text(1, 9, "angle", adj = 0); text(2.5, 9, "\\320")
> text(3, 9, expression(symbol("\320")))
> text(1, 10, "leftangle", adj = 0); text(2.5, 10, "\\341")
> text(3, 10, expression(symbol("\341")))
> text(1, 11, "rightangle", adj = 0); text(2.5, 11, "\\361")
> text(3, 11, expression(symbol("\361")))
>
>
>
> cleanEx()
> nameEx("postscriptFonts")
> ### * postscriptFonts
>
> flush(stderr()); flush(stdout())
>
> ### Name: postscriptFonts
> ### Title: PostScript and PDF Font Families
> ### Aliases: postscriptFonts pdfFonts
> ### Keywords: device
>
> ### ** Examples
>
> postscriptFonts()
$serif
$family
[1] "Times"
$metrics
[1] "Times-Roman.afm" "Times-Bold.afm" "Times-Italic.afm"
[4] "Times-BoldItalic.afm" "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$sans
$family
[1] "Helvetica"
$metrics
[1] "Helvetica.afm" "Helvetica-Bold.afm"
[3] "Helvetica-Oblique.afm" "Helvetica-BoldOblique.afm"
[5] "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$mono
$family
[1] "Courier"
$metrics
[1] "Courier.afm" "Courier-Bold.afm"
[3] "Courier-Oblique.afm" "Courier-BoldOblique.afm"
[5] "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$AvantGarde
$family
[1] "AvantGarde"
$metrics
[1] "agw_____.afm" "agd_____.afm" "agwo____.afm" "agdo____.afm" "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$Bookman
$family
[1] "Bookman"
$metrics
[1] "bkl_____.afm" "bkd_____.afm" "bkli____.afm" "bkdi____.afm" "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$Courier
$family
[1] "Courier"
$metrics
[1] "Courier.afm" "Courier-Bold.afm"
[3] "Courier-Oblique.afm" "Courier-BoldOblique.afm"
[5] "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$Helvetica
$family
[1] "Helvetica"
$metrics
[1] "Helvetica.afm" "Helvetica-Bold.afm"
[3] "Helvetica-Oblique.afm" "Helvetica-BoldOblique.afm"
[5] "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$`Helvetica-Narrow`
$family
[1] "Helvetica-Narrow"
$metrics
[1] "hvn_____.afm" "hvnb____.afm" "hvno____.afm" "hvnbo___.afm" "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$NewCenturySchoolbook
$family
[1] "NewCenturySchoolbook"
$metrics
[1] "ncr_____.afm" "ncb_____.afm" "nci_____.afm" "ncbi____.afm" "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$Palatino
$family
[1] "Palatino"
$metrics
[1] "por_____.afm" "pob_____.afm" "poi_____.afm" "pobi____.afm" "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$Times
$family
[1] "Times"
$metrics
[1] "Times-Roman.afm" "Times-Bold.afm" "Times-Italic.afm"
[4] "Times-BoldItalic.afm" "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$URWGothic
$family
[1] "URWGothic"
$metrics
[1] "a010013l.afm" "a010015l.afm" "a010033l.afm" "a010035l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$URWBookman
$family
[1] "URWBookman"
$metrics
[1] "b018012l.afm" "b018015l.afm" "b018032l.afm" "b018035l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$NimbusMon
$family
[1] "NimbusMon"
$metrics
[1] "n022003l.afm" "n022004l.afm" "n022023l.afm" "n022024l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$NimbusSan
$family
[1] "NimbusSan"
$metrics
[1] "n019003l.afm" "n019004l.afm" "n019023l.afm" "n019024l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$URWHelvetica
$family
[1] "URWHelvetica"
$metrics
[1] "n019003l.afm" "n019004l.afm" "n019023l.afm" "n019024l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$NimbusSanCond
$family
[1] "NimbusSanCond"
$metrics
[1] "n019043l.afm" "n019044l.afm" "n019063l.afm" "n019064l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$CenturySch
$family
[1] "CenturySch"
$metrics
[1] "c059013l.afm" "c059016l.afm" "c059033l.afm" "c059036l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$URWPalladio
$family
[1] "URWPalladio"
$metrics
[1] "p052003l.afm" "p052004l.afm" "p052023l.afm" "p052024l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$NimbusRom
$family
[1] "NimbusRom"
$metrics
[1] "n021003l.afm" "n021004l.afm" "n021023l.afm" "n021024l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$URWTimes
$family
[1] "URWTimes"
$metrics
[1] "n021003l.afm" "n021004l.afm" "n021023l.afm" "n021024l.afm" "s050000l.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$ArialMT
$family
[1] "ArialMT"
$metrics
[1] "ArialMT.afm" "ArialMT-Bold.afm" "ArialMT-Italic.afm"
[4] "ArialMT-BoldItalic.afm" "Symbol.afm"
$encoding
[1] "default"
attr(,"class")
[1] "Type1Font"
$ComputerModern
$family
[1] "ComputerModern"
$metrics
[1] "CM_regular_10.afm" "CM_boldx_10.afm" "CM_italic_10.afm"
[4] "CM_boldx_italic_10.afm" "CM_symbol_10.afm"
$encoding
[1] "TeXtext.enc"
attr(,"class")
[1] "Type1Font"
$ComputerModernItalic
$family
[1] "ComputerModernItalic"
$metrics
[1] "CM_regular_10.afm" "CM_boldx_10.afm" "cmti10.afm"
[4] "cmbxti10.afm" "CM_symbol_10.afm"
$encoding
[1] "TeXtext.enc"
attr(,"class")
[1] "Type1Font"
$Japan1
$family
[1] "HeiseiKakuGo-W5"
$metrics
[1] "" "" "" "" "Symbol.afm"
$cmap
[1] "EUC-H"
$cmapEncoding
[1] "EUC-JP"
$pdfresource
[1] ""
attr(,"class")
[1] "CIDFont"
$Japan1HeiMin
$family
[1] "HeiseiMin-W3"
$metrics
[1] "" "" "" "" "Symbol.afm"
$cmap
[1] "EUC-H"
$cmapEncoding
[1] "EUC-JP"
$pdfresource
[1] ""
attr(,"class")
[1] "CIDFont"
$Japan1GothicBBB
$family
[1] "GothicBBB-Medium"
$metrics
[1] "" "" "" "" "Symbol.afm"
$cmap
[1] "EUC-H"
$cmapEncoding
[1] "EUC-JP"
$pdfresource
[1] ""
attr(,"class")
[1] "CIDFont"
$Japan1Ryumin
$family
[1] "Ryumin-Light"
$metrics
[1] "" "" "" "" "Symbol.afm"
$cmap
[1] "EUC-H"
$cmapEncoding
[1] "EUC-JP"
$pdfresource
[1] ""
attr(,"class")
[1] "CIDFont"
$Korea1
$family
[1] "Baekmuk-Batang"
$metrics
[1] "" "" "" "" "Symbol.afm"
$cmap
[1] "KSCms-UHC-H"
$cmapEncoding
[1] "CP949"
$pdfresource
[1] ""
attr(,"class")
[1] "CIDFont"
$Korea1deb
$family
[1] "Batang-Regular"
$metrics
[1] "" "" "" "" "Symbol.afm"
$cmap
[1] "KSCms-UHC-H"
$cmapEncoding
[1] "CP949"
$pdfresource
[1] ""
attr(,"class")
[1] "CIDFont"
$CNS1
$family
[1] "MOESung-Regular"
$metrics
[1] "" "" "" "" "Symbol.afm"
$cmap
[1] "B5pc-H"
$cmapEncoding
[1] "CP950"
$pdfresource
[1] ""
attr(,"class")
[1] "CIDFont"
$GB1
$family
[1] "BousungEG-Light-GB"
$metrics
[1] "" "" "" "" "Symbol.afm"
$cmap
[1] "GBK-EUC-H"
$cmapEncoding
[1] "GBK"
$pdfresource
[1] ""
attr(,"class")
[1] "CIDFont"
> ## This duplicates "ComputerModernItalic".
> CMitalic <- Type1Font("ComputerModern2",
+ c("CM_regular_10.afm", "CM_boldx_10.afm",
+ "cmti10.afm", "cmbxti10.afm",
+ "CM_symbol_10.afm"),
+ encoding = "TeXtext.enc")
> postscriptFonts(CMitalic = CMitalic)
>
> ## A CID font for Japanese using a different CMap and
> ## corresponding cmapEncoding.
> `Jp_UCS-2` <- CIDFont("TestUCS2",
+ c("Adobe-Japan1-UniJIS-UCS2-H.afm",
+ "Adobe-Japan1-UniJIS-UCS2-H.afm",
+ "Adobe-Japan1-UniJIS-UCS2-H.afm",
+ "Adobe-Japan1-UniJIS-UCS2-H.afm"),
+ "UniJIS-UCS2-H", "UCS-2")
> pdfFonts(`Jp_UCS-2` = `Jp_UCS-2`)
> names(pdfFonts())
[1] "serif" "sans" "mono"
[4] "AvantGarde" "Bookman" "Courier"
[7] "Helvetica" "Helvetica-Narrow" "NewCenturySchoolbook"
[10] "Palatino" "Times" "URWGothic"
[13] "URWBookman" "NimbusMon" "NimbusSan"
[16] "URWHelvetica" "NimbusSanCond" "CenturySch"
[19] "URWPalladio" "NimbusRom" "URWTimes"
[22] "ArialMT" "Japan1" "Japan1HeiMin"
[25] "Japan1GothicBBB" "Japan1Ryumin" "Korea1"
[28] "Korea1deb" "CNS1" "GB1"
[31] "Jp_UCS-2"
>
>
>
> cleanEx()
> nameEx("pretty.Date")
> ### * pretty.Date
>
> flush(stderr()); flush(stdout())
>
> ### Name: pretty.Date
> ### Title: Pretty Breakpoints for Date-Time Classes
> ### Aliases: pretty.Date pretty.POSIXt
> ### Keywords: dplot
>
> ### ** Examples
>
>
> steps <-
+ list("10 secs", "1 min", "5 mins", "30 mins", "6 hours", "12 hours",
+ "1 DSTday", "2 weeks", "1 month", "6 months", "1 year",
+ "10 years", "50 years", "1000 years")
>
> names(steps) <- paste("span =", unlist(steps))
>
> x <- as.POSIXct("2002-02-02 02:02")
> lapply(steps,
+ function(s) {
+ at <- pretty(seq(x, by = s, length = 2), n = 5)
+ attr(at, "labels")
+ })
$`span = 10 secs`
[1] "00" "02" "04" "06" "08" "10"
$`span = 1 min`
[1] "00" "10" "20" "30" "40" "50" "00"
$`span = 5 mins`
[1] "02:02" "02:03" "02:04" "02:05" "02:06" "02:07"
$`span = 30 mins`
[1] "02:05" "02:10" "02:15" "02:20" "02:25" "02:30"
$`span = 6 hours`
[1] "03:00" "04:00" "05:00" "06:00" "07:00" "08:00"
$`span = 12 hours`
[1] "03:00" "06:00" "09:00" "12:00"
$`span = 1 DSTday`
[1] "Feb 02 06:00" "Feb 02 12:00" "Feb 02 18:00" "Feb 03 00:00"
$`span = 2 weeks`
[1] "Feb 04" "Feb 06" "Feb 08" "Feb 10" "Feb 12" "Feb 14" "Feb 16"
$`span = 1 month`
[1] "Feb 04" "Feb 11" "Feb 18" "Feb 25"
$`span = 6 months`
[1] "Mar" "Apr" "May" "Jun" "Jul" "Aug"
$`span = 1 year`
[1] "Apr" "Jul" "Oct" "Jan"
$`span = 10 years`
[1] "2004" "2006" "2008" "2010" "2012"
$`span = 50 years`
[1] "2010" "2020" "2030" "2040" "2050"
$`span = 1000 years`
[1] "2200" "2400" "2600" "2800" "3000"
>
>
>
>
> cleanEx()
> nameEx("ps.options")
> ### * ps.options
>
> flush(stderr()); flush(stdout())
>
> ### Name: ps.options
> ### Title: Auxiliary Function to Set/View Defaults for Arguments of
> ### postscript
> ### Aliases: ps.options setEPS setPS
> ### Keywords: device
>
> ### ** Examples
>
> ps.options(bg = "pink")
> utils::str(ps.options())
List of 18
$ onefile : logi TRUE
$ family : chr "Helvetica"
$ title : chr "R Graphics Output"
$ fonts : NULL
$ encoding : chr "default"
$ bg : chr "pink"
$ fg : chr "black"
$ width : num 0
$ height : num 0
$ horizontal : logi TRUE
$ pointsize : num 12
$ paper : chr "default"
$ pagecentre : logi TRUE
$ print.it : logi FALSE
$ command : chr "default"
$ colormodel : chr "srgb"
$ useKerning : logi TRUE
$ fillOddEven: logi FALSE
>
> ### ---- error checking of arguments: ----
> ps.options(width = 0:12, onefile = 0, bg = pi)
Warning: ‘mode(onefile)’ and ‘mode(bg)’ differ between new and previous
==> NOT changing ‘onefile’ & ‘bg’
Warning: ‘length(width)’ differs between new and previous
==> NOT changing ‘width’
> # override the check for 'width', but not 'bg':
> ps.options(width = 0:12, bg = pi, override.check = c(TRUE,FALSE))
Warning: ‘mode(bg)’ differs between new and previous
==> NOT changing ‘bg’
Warning: ‘length(width)’ differs between new and previous
> utils::str(ps.options())
List of 18
$ onefile : logi TRUE
$ family : chr "Helvetica"
$ title : chr "R Graphics Output"
$ fonts : NULL
$ encoding : chr "default"
$ bg : chr "pink"
$ fg : chr "black"
$ width : int [1:13] 0 1 2 3 4 5 6 7 8 9 ...
$ height : num 0
$ horizontal : logi TRUE
$ pointsize : num 12
$ paper : chr "default"
$ pagecentre : logi TRUE
$ print.it : logi FALSE
$ command : chr "default"
$ colormodel : chr "srgb"
$ useKerning : logi TRUE
$ fillOddEven: logi FALSE
> ps.options(reset = TRUE) # back to factory-fresh
>
>
>
> cleanEx()
> nameEx("recordGraphics")
> ### * recordGraphics
>
> flush(stderr()); flush(stdout())
>
> ### Name: recordGraphics
> ### Title: Record Graphics Operations
> ### Aliases: recordGraphics
> ### Keywords: device
>
> ### ** Examples
>
> require(graphics)
>
> plot(1:10)
> # This rectangle remains 1inch wide when the device is resized
> recordGraphics(
+ {
+ rect(4, 2,
+ 4 + diff(par("usr")[1:2])/par("pin")[1], 3)
+ },
+ list(),
+ getNamespace("graphics"))
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("rgb")
> ### * rgb
>
> flush(stderr()); flush(stdout())
>
> ### Name: rgb
> ### Title: RGB Color Specification
> ### Aliases: rgb
> ### Keywords: color
>
> ### ** Examples
>
> rgb(0, 1, 0)
[1] "#00FF00"
>
> rgb((0:15)/15, green = 0, blue = 0, names = paste("red", 0:15, sep = "."))
red.0 red.1 red.2 red.3 red.4 red.5 red.6 red.7
"#000000" "#110000" "#220000" "#330000" "#440000" "#550000" "#660000" "#770000"
red.8 red.9 red.10 red.11 red.12 red.13 red.14 red.15
"#880000" "#990000" "#AA0000" "#BB0000" "#CC0000" "#DD0000" "#EE0000" "#FF0000"
>
> rgb(0, 0:12, 0, max = 255) # integer input
[1] "#000000" "#000100" "#000200" "#000300" "#000400" "#000500" "#000600"
[8] "#000700" "#000800" "#000900" "#000A00" "#000B00" "#000C00"
>
> ramp <- colorRamp(c("red", "white"))
> rgb( ramp(seq(0, 1, length = 5)), max = 255)
[1] "#FF0000" "#FF3F3F" "#FF7F7F" "#FFBFBF" "#FFFFFF"
>
>
>
> cleanEx()
> nameEx("rgb2hsv")
> ### * rgb2hsv
>
> flush(stderr()); flush(stdout())
>
> ### Name: rgb2hsv
> ### Title: RGB to HSV Conversion
> ### Aliases: rgb2hsv
> ### Keywords: color dplot
>
> ### ** Examples
>
> ## These (saturated, bright ones) only differ by hue
> (rc <- col2rgb(c("red", "yellow","green","cyan", "blue", "magenta")))
[,1] [,2] [,3] [,4] [,5] [,6]
red 255 255 0 0 0 255
green 0 255 255 255 0 0
blue 0 0 0 255 255 255
> (hc <- rgb2hsv(rc))
[,1] [,2] [,3] [,4] [,5] [,6]
h 0 0.1666667 0.3333333 0.5 0.6666667 0.8333333
s 1 1.0000000 1.0000000 1.0 1.0000000 1.0000000
v 1 1.0000000 1.0000000 1.0 1.0000000 1.0000000
> 6 * hc["h",] # the hues are equispaced
[1] 0 1 2 3 4 5
>
> ## Don't show:
> set.seed(151)
> ## End Don't show
> (rgb3 <- floor(256 * matrix(stats::runif(3*12), 3, 12)))
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,] 122 137 116 244 20 153 191 250 134 117 27 202
[2,] 221 113 210 200 218 151 64 182 195 103 218 254
[3,] 199 157 88 76 39 91 80 146 22 105 17 239
> (hsv3 <- rgb2hsv(rgb3))
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
h 0.4629630 0.7575758 0.2950820 0.1230159 0.3493266 0.1612903 0.9790026
s 0.4479638 0.2802548 0.5809524 0.6885246 0.9082569 0.4052288 0.6649215
v 0.8666667 0.6156863 0.8235294 0.9568627 0.8549020 0.6000000 0.7490196
[,8] [,9] [,10] [,11] [,12]
h 0.05769231 0.2254335 0.9761905 0.3250415 0.4519231
s 0.41600000 0.8871795 0.1196581 0.9220183 0.2047244
v 0.98039216 0.7647059 0.4588235 0.8549020 0.9960784
> ## Consistency :
> stopifnot(rgb3 == col2rgb(hsv(h = hsv3[1,], s = hsv3[2,], v = hsv3[3,])),
+ all.equal(hsv3, rgb2hsv(rgb3/255, maxColorValue = 1)))
>
> ## A (simplified) pure R version -- originally by Wolfram Fischer --
> ## showing the exact algorithm:
> rgb2hsvR <- function(rgb, gamma = 1, maxColorValue = 255)
+ {
+ if(!is.numeric(rgb)) stop("rgb matrix must be numeric")
+ d <- dim(rgb)
+ if(d[1] != 3) stop("rgb matrix must have 3 rows")
+ n <- d[2]
+ if(n == 0) return(cbind(c(h = 1, s = 1, v = 1))[,0])
+ rgb <- rgb/maxColorValue
+ if(gamma != 1) rgb <- rgb ^ (1/gamma)
+
+ ## get the max and min
+ v <- apply( rgb, 2, max)
+ s <- apply( rgb, 2, min)
+ D <- v - s # range
+
+ ## set hue to zero for undefined values (gray has no hue)
+ h <- numeric(n)
+ notgray <- ( s != v )
+
+ ## blue hue
+ idx <- (v == rgb[3,] & notgray )
+ if (any (idx))
+ h[idx] <- 2/3 + 1/6 * (rgb[1,idx] - rgb[2,idx]) / D[idx]
+ ## green hue
+ idx <- (v == rgb[2,] & notgray )
+ if (any (idx))
+ h[idx] <- 1/3 + 1/6 * (rgb[3,idx] - rgb[1,idx]) / D[idx]
+ ## red hue
+ idx <- (v == rgb[1,] & notgray )
+ if (any (idx))
+ h[idx] <- 1/6 * (rgb[2,idx] - rgb[3,idx]) / D[idx]
+
+ ## correct for negative red
+ idx <- (h < 0)
+ h[idx] <- 1+h[idx]
+
+ ## set the saturation
+ s[! notgray] <- 0;
+ s[notgray] <- 1 - s[notgray] / v[notgray]
+
+ rbind( h = h, s = s, v = v )
+ }
>
> ## confirm the equivalence:
> all.equal(rgb2hsv (rgb3),
+ rgb2hsvR(rgb3), tolerance = 1e-14) # TRUE
[1] TRUE
>
>
>
> cleanEx()
> nameEx("trans3d")
> ### * trans3d
>
> flush(stderr()); flush(stdout())
>
> ### Name: trans3d
> ### Title: 3D to 2D Transformation for Perspective Plots
> ### Aliases: trans3d
> ### Keywords: dplot
>
> ### ** Examples
>
> ## See help(persp) {after attaching the 'graphics' package}
> ## -----------
>
>
>
> cleanEx()
> nameEx("xy.coords")
> ### * xy.coords
>
> flush(stderr()); flush(stdout())
>
> ### Name: xy.coords
> ### Title: Extracting Plotting Structures
> ### Aliases: xy.coords
> ### Keywords: dplot
>
> ### ** Examples
>
> xy.coords(stats::fft(c(1:9)), NULL)
$x
[1] 45.0 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5 -4.5
$y
[1] 0.0000000 12.3636484 5.3628912 2.5980762 0.7934714 -0.7934714
[7] -2.5980762 -5.3628912 -12.3636484
$xlab
[1] "Re()"
$ylab
[1] "Im()"
>
> with(cars, xy.coords(dist ~ speed, NULL)$xlab ) # = "speed"
[1] "speed"
>
> xy.coords(1:3, 1:2, recycle = TRUE)
$x
[1] 1 2 3
$y
[1] 1 2 1
$xlab
NULL
$ylab
NULL
> xy.coords(-2:10, NULL, log = "y")
Warning in xy.coords(-2:10, NULL, log = "y") :
3 y values <= 0 omitted from logarithmic plot
$x
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13
$y
[1] NA NA NA 1 2 3 4 5 6 7 8 9 10
$xlab
[1] "Index"
$ylab
NULL
> ##> warning: 3 y values <= 0 omitted ..
>
>
>
> cleanEx()
> nameEx("xyTable")
> ### * xyTable
>
> flush(stderr()); flush(stdout())
>
> ### Name: xyTable
> ### Title: Multiplicities of (x,y) Points, e.g., for a Sunflower Plot
> ### Aliases: xyTable
> ### Keywords: dplot
>
> ### ** Examples
>
> xyTable(iris[, 3:4], digits = 6)
$x
[1] 1.0 1.1 1.2 1.3 1.3 1.3 1.4 1.4 1.4 1.5 1.5 1.5 1.5 1.6 1.6 1.6 1.7 1.7
[19] 1.7 1.7 1.9 1.9 3.0 3.3 3.5 3.6 3.7 3.8 3.9 3.9 3.9 4.0 4.0 4.0 4.1 4.1
[37] 4.2 4.2 4.2 4.3 4.4 4.4 4.4 4.5 4.5 4.5 4.5 4.6 4.6 4.6 4.7 4.7 4.7 4.7
[55] 4.8 4.8 4.9 4.9 4.9 5.0 5.0 5.0 5.0 5.1 5.1 5.1 5.1 5.1 5.1 5.1 5.2 5.2
[73] 5.3 5.3 5.4 5.4 5.5 5.5 5.6 5.6 5.6 5.6 5.6 5.7 5.7 5.7 5.8 5.8 5.8 5.9
[91] 5.9 6.0 6.0 6.1 6.1 6.1 6.3 6.4 6.6 6.7 6.7 6.9
$y
[1] 0.2 0.1 0.2 0.2 0.3 0.4 0.1 0.2 0.3 0.1 0.2 0.3 0.4 0.2 0.4 0.6 0.2 0.3
[19] 0.4 0.5 0.2 0.4 1.1 1.0 1.0 1.3 1.0 1.1 1.1 1.2 1.4 1.0 1.2 1.3 1.0 1.3
[37] 1.2 1.3 1.5 1.3 1.2 1.3 1.4 1.3 1.5 1.6 1.7 1.3 1.4 1.5 1.2 1.4 1.5 1.6
[55] 1.4 1.8 1.5 1.8 2.0 1.5 1.7 1.9 2.0 1.5 1.6 1.8 1.9 2.0 2.3 2.4 2.0 2.3
[73] 1.9 2.3 2.1 2.3 1.8 2.1 1.4 1.8 2.1 2.2 2.4 2.1 2.3 2.5 1.6 1.8 2.2 2.1
[91] 2.3 1.8 2.5 1.9 2.3 2.5 1.8 2.0 2.1 2.0 2.2 2.3
$number
[1] 1 1 2 4 2 1 2 8 3 2 7 1 3 5 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 3 1 2 1
[38] 2 1 2 1 1 2 1 5 1 1 1 1 1 1 2 1 1 1 3 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1
[75] 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>
> ## Discretized uncorrelated Gaussian:
> ## Don't show:
> set.seed(1)
> ## End Don't show
> require(stats)
> xy <- data.frame(x = round(sort(rnorm(100))), y = rnorm(100))
> xyTable(xy, digits = 1)
$x
[1] -2 -2 -2 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0
[26] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
[51] 1 1 1 1 1 1 2 2 2 2
$y
[1] -0.90 -0.60 0.04 0.20 -0.70 -0.60 -0.50 -0.40 -0.30 -0.20 -0.10 0.40
[13] 0.50 0.70 0.90 1.00 2.00 -2.00 -1.00 -0.90 -0.80 -0.70 -0.60 -0.50
[25] -0.30 -0.20 -0.07 -0.06 -0.04 -0.02 0.02 0.06 0.30 0.40 0.50 0.70
[37] 0.90 1.00 2.00 -1.00 -0.90 -0.80 -0.70 -0.40 -0.30 -0.20 -0.10 -0.08
[49] -0.03 0.10 0.20 0.40 0.50 0.80 1.00 2.00 -1.00 -0.40 0.40 1.00
$number
[1] 1 1 1 1 2 1 2 1 2 4 1 1 1 1 1 2 2 5 5 1 1 2 3 2 3 1 1 1 1 1 1 1 1 1 2 1 1 3
[39] 3 3 1 1 1 1 2 2 1 1 1 1 2 1 2 2 4 2 3 1 1 1
>
>
>
> cleanEx()
> nameEx("xyz.coords")
> ### * xyz.coords
>
> flush(stderr()); flush(stdout())
>
> ### Name: xyz.coords
> ### Title: Extracting Plotting Structures
> ### Aliases: xyz.coords
> ### Keywords: dplot
>
> ### ** Examples
>
> xyz.coords(data.frame(10*1:9, -4), y = NULL, z = NULL)
$x
[1] 1 2 3 4 5 6 7 8 9
$y
[1] 10 20 30 40 50 60 70 80 90
$z
[1] -4 -4 -4 -4 -4 -4 -4 -4 -4
$xlab
[1] "Index"
$ylab
NULL
$zlab
NULL
>
> xyz.coords(1:5, stats::fft(1:5), z = NULL, xlab = "X", ylab = "Y")
$x
[1] 15.0 -2.5 -2.5 -2.5 -2.5
$y
[1] 0.0000000 3.4409548 0.8122992 -0.8122992 -3.4409548
$z
[1] 1 2 3 4 5
$xlab
[1] "Re(Y)"
$ylab
[1] "Im(Y)"
$zlab
[1] "X"
>
> y <- 2 * (x2 <- 10 + (x1 <- 1:10))
> xyz.coords(y ~ x1 + x2, y = NULL, z = NULL)
$x
[1] 1 2 3 4 5 6 7 8 9 10
$y
[1] 11 12 13 14 15 16 17 18 19 20
$z
[1] 22 24 26 28 30 32 34 36 38 40
$xlab
[1] "x1"
$ylab
[1] "x2"
$zlab
[1] "y"
>
> xyz.coords(data.frame(x = -1:9, y = 2:12, z = 3:13), y = NULL, z = NULL,
+ log = "xy")
Warning in xyz.coords(data.frame(x = -1:9, y = 2:12, z = 3:13), y = NULL, :
2 x values <= 0 omitted from logarithmic plot
$x
[1] NA NA 1 2 3 4 5 6 7 8 9
$y
[1] 2 3 4 5 6 7 8 9 10 11 12
$z
[1] 3 4 5 6 7 8 9 10 11 12 13
$xlab
[1] "x"
$ylab
[1] "y"
$zlab
[1] "z"
> ##> Warning message: 2 x values <= 0 omitted ...
>
>
>
> ### * <FOOTER>
> ###
> options(digits = 7L)
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
Time elapsed: 10.005 0.172 10.244 0 0
> grDevices::dev.off()
null device
1
> ###
> ### Local variables: ***
> ### mode: outline-minor ***
> ### outline-regexp: "\\(> \\)?### [*]+" ***
> ### End: ***
> quit('no')
|