发布在ggplot2中绘制“高分辨率”行数据的问题

时间:2014-01-10 00:13:04

标签: r ggplot2

我有一些数据,我想在ggplot2中绘制为简单的线条。线条不直,它们在许多地方弯曲和交叉。我可以使用

在散点图中将它们绘制为符号
qplot(x, y, data=test)

当线条出现时,符号太大,因此线条太粗。我似乎无法使用例如size=I(1)来减小厚度。

我尝试使用geom="line"geom="path",但后来我出现了不应该出现的地方。例如,如果我使用

绘图
qplot(x, y, data=test, geom="line")

ggplot2当然在所有相邻值之间绘制一条线。我不能简单地按顺序放置我的数据,因为它是一组复杂的线交叉,等等。如果我使用

绘图
qplot(x, y, data=test, geom="path")

我又遇到了类似的问题。

我希望有人可以建议一个绘制数据的好方法。整个数据集大约有5000个点,但我在这里提供了一个小样本:

test <- structure(list(x = c(608.0515, 601.9633, 595.8752, 589.787, 583.6989, 
577.6107, 571.5226, 565.4344, 559.3463, 553.2582, 547.17, 541.0819, 
534.9937, 528.9056, 522.8174, 516.7292, 510.6411, 504.553, 857.7537, 
851.6655, 845.5774, 839.4893, 833.4011, 827.313, 821.2248, 815.1367, 
809.0485, 802.9604, 796.8721, 790.7841, 784.6959, 778.6078, 772.5197, 
766.4315, 760.3434, 754.2551, 748.1671, 742.0789, 735.9908, 729.9026, 
723.8145, 717.7263, 711.6381, 705.5501, 699.4619, 693.3738, 687.2856, 
681.1975, 675.1093, 669.0212, 662.933, 656.8449, 650.7567, 644.6686, 
638.5805, 632.4923, 626.4042, 620.316, 614.2279, 1016.1337, 1010.0456, 
1003.9574, 997.8693, 991.7812, 985.693, 979.6049, 973.5167, 967.4285, 
961.3404, 955.2523, 949.1641, 943.076, 936.9878, 930.8997, 924.8115, 
918.7234, 912.6353, 906.5471, 900.459, 894.3708, 888.2827, 882.1945, 
876.1064, 870.0182, 863.9301, 1113.6322, 1107.5442, 1101.456, 
1095.3679, 1089.2797, 1083.1916, 1077.1035, 1071.0153, 1064.9272, 
1058.839, 1052.7509, 1046.6627, 1040.5746, 1034.4864, 1028.3982, 
1022.3101, 1186.7783, 1180.6902, 1174.6019, 1168.5139, 1162.4257, 
1156.3376, 1150.2495, 1144.1613, 1138.0732, 1131.9849, 1125.8969, 
1119.8087, 504.8178, 1284.2769, 1278.1888, 1272.1006, 1266.0125, 
1259.9243, 1253.8362, 1247.748, 1241.6599, 1235.5718, 1229.4836, 
1223.3955, 1217.3073, 1211.2192, 1205.131, 1199.0429, 1192.9546, 
504.906, 1351.3348, 1345.2466, 1339.1585, 1333.0703, 1326.9822, 
1320.8941, 1314.8058, 1308.7178, 1302.6296, 1296.5415, 1290.4533, 
511.0825, 504.9943, 1406.2164, 1400.1282, 1394.0401, 1387.9519, 
1381.8638, 1375.7755, 1369.6875, 1363.5993, 1357.5112, 1455.0098, 
1448.9216, 1442.8335, 1436.7452, 511.1707, 1430.6572, 1424.5691, 
1418.4809, 1412.3928, 1509.8914, 1503.8032, 1497.7151, 1491.6269, 
1485.5388, 1479.4506, 1473.3625, 1467.2743, 1461.1862, 517.3471, 
1546.5085, 1540.4203, 1534.3322, 1528.2441, 1522.1559, 1516.0678, 
517.4354, 1583.1256, 1577.0375, 1570.9493, 1564.8612, 1558.773, 
1552.6848, 523.6118, 1631.9191, 1625.8309, 1625.8309, 1619.7428, 
1613.6545, 1607.5665, 1601.4783, 1595.3902, 1589.302, 523.7001, 
1668.5362, 1662.448, 1656.3599, 1650.2718, 1644.1836, 1638.0955, 
1638.0955, 1632.0073, 1632.0073, 529.8765, 1705.1533, 1699.0652, 
1692.9769, 1686.8889, 1680.8007, 1674.7126, 1644.2719, 529.9647, 
1735.6823, 1729.5941, 1723.506, 1717.4179, 1711.3296, 1644.3601, 
536.1412, 1760.1232, 1754.035, 1747.9468, 1741.8587, 1650.5365, 
542.3176, 1790.6522, 1784.564, 1778.4759, 1772.3877, 1766.2995, 
1656.713, 548.494, 1815.093, 1809.0049, 1802.9167, 1796.8286, 
1662.8894, 548.5822, 1857.7983, 1851.7101, 1845.6219, 1839.5338, 
1833.4457, 1827.3576, 1821.2694, 1669.0658, 548.6705, 1669.154, 
554.8469, 1675.3304, 554.9352, 1675.4187, 561.1116, 1681.5951, 
567.288, 1687.7715, 567.3763, 1693.9479, 573.5527, 1700.1243, 
573.6409, 1700.2126, 579.8173, 1706.389, 585.9937, 1712.5654, 
586.082, 1712.6537, 592.2584, 1718.83, 598.4348, 1725.0065, 598.5231, 
1725.0948, 604.6995, 1731.2711, 610.8759, 604.7877, 1737.4476, 
617.0523, 1737.5359, 617.1406, 1743.7123, 623.317, 1749.8887, 
629.4934, 623.4053, 1749.9769, 635.6698, 1756.1533, 635.7581, 
1762.3298, 641.9344, 1768.5062, 648.1109, 642.0227, 1768.5944, 
648.1992, 1774.7708, 654.3756, 1774.8591, 660.552, 1781.0355, 
666.7284, 660.6402, 1787.2119, 666.8166, 1793.3883, 672.9931, 
1793.4766, 679.1695, 1793.5649, 685.3458, 679.2577, 1799.7412, 
685.4341, 1805.9177, 691.6105, 1812.0941, 697.787, 1812.1823, 
703.9634, 697.8752, 1818.3588, 704.0516, 1818.447, 710.228, 1818.5352, 
716.4043, 1824.7117, 716.4927, 1830.8881, 722.6691, 1830.9764, 
728.8455, 1837.1528, 728.9338, 1843.3292, 735.1102, 1843.4174, 
735.1985, 1849.5939, 741.3749, 1849.6821, 747.5513, 1849.7704, 
747.6395, 1855.9468, 753.8159, 1862.1232, 759.9924, 1862.2115, 
760.0806, 1868.3879, 766.257, 1868.4761, 766.3453, 1874.6524, 
772.5217, 1880.829, 778.6981, 1880.9172, 778.7864, 1881.0055, 
784.9628, 1887.1819, 785.0511, 1893.3583, 791.2275, 1893.4466, 
797.4039, 1899.623, 797.4921, 1899.7112, 797.5804, 1905.8876, 
1899.7995, 803.7568, 1905.9759, 809.9332, 1912.1522, 810.0215, 
1912.2406, 816.1979, 1918.417, 1912.3288, 816.2862, 1918.5053, 
822.4626, 1924.6817, 828.639, 1924.7699, 828.7271, 1930.9463, 
1924.8582, 828.8155, 1931.0346, 834.9919, 1937.211, 841.1683, 
1937.2993, 841.2566, 1943.4757, 841.3448, 1949.6521, 847.5213, 
1949.7404, 847.6095, 1949.8286, 853.7859, 1956.005, 1949.9169, 
853.8742, 1956.0933, 860.0506, 1962.2697, 860.1389, 1962.358, 
866.3153, 1968.5344, 866.4035, 1968.6226, 872.5798, 1968.7109, 
872.6682, 1974.8873, 872.7565, 1981.0637, 878.9329, 1981.152, 
885.1093, 1981.2402, 885.1976, 1987.4167, 1981.3285, 885.2858, 
1987.5049, 891.4622, 1993.6813, 891.5505, 1993.7696, 897.7269, 
1993.8578, 897.8152, 2000.0343, 903.9916, 2000.1225, 904.0798, 
2006.2989, 904.1681, 2012.4753, 910.3445, 2012.5636, 916.5209, 
2012.6519, 916.6092, 2018.8283, 2012.7401, 916.6974, 2018.9165, 
922.8739, 2025.093, 922.9621, 2025.1812, 923.0504, 2031.3576, 
929.2268, 2031.4459, 929.3151, 2031.5342, 929.4033, 2037.7106, 
935.5796, 2037.7988, 935.668, 2037.8871, 941.8444, 2044.0635, 
941.9327, 2044.1518, 948.1091, 2050.3282, 948.1973, 2050.4163, 
948.2856, 2056.5929, 954.462, 2056.6811, 954.5503, 2056.7694, 
954.6385, 2062.9458, 2056.8576, 960.8149, 2063.0341, 960.9032, 
2069.2105, 960.9915, 2069.2987, 967.1679, 2069.387, 967.2561, 
2075.5634, 967.3444, 2075.6517, 973.5208, 2081.8281, 973.6091, 
2081.9163, 979.7854, 2082.0046, 979.8738, 2088.181, 979.962, 
2088.2692, 986.1384, 2088.3575, 986.2267, 2094.5339, 986.315, 
2094.6221, 992.4914, 2094.7105, 992.5796, 2100.8869, 992.6679, 
2100.975, 998.8443, 2101.0634, 998.9325, 2107.2398, 999.0208, 
2107.3281, 1005.1972, 2107.4163, 1005.2854, 2113.5928, 1005.3738, 
2113.681, 1011.5502, 2119.8574, 1011.6383, 2119.9457, 1011.7267, 
2120.034, 1017.9031, 2126.2104, 1017.9914, 2126.2986, 1018.0796, 
2126.3869, 1018.1679, 2126.4752, 1024.3443, 2132.6516, 1024.4325, 
2132.7398, 1030.609, 2132.8281, 1030.6973, 2139.0045, 1030.7854, 
2139.0928, 1036.9619, 2145.2692, 1037.0502, 2145.3574, 1037.1385, 
2145.4457, 1037.2267, 2151.6221, 1037.315, 2151.7104, 1043.4914, 
2151.7986, 1043.5796, 2157.975, 1043.6679, 2158.0633, 1049.8443, 
2158.1516, 1049.9325, 2164.328, 1050.0209, 2164.4162, 1050.1091, 
2164.5045, 1056.2854, 2164.5928, 1056.3738, 2170.7692, 1056.4621, 
2170.8574, 1062.6385, 2170.9457, 1062.7267, 2177.1221, 1062.815, 
2177.2104, 1062.9033, 2177.2986, 1069.0796, 2183.4751, 1069.1679, 
2183.5633, 1069.2562, 2183.6516, 1069.3445, 2183.7398, 1075.5209, 
2189.9163, 1075.6091, 2190.0045, 1075.6974, 2190.0928, 1081.8738, 
2196.2692, 1081.9621, 2196.3575, 1082.0503, 2196.4457, 1082.1386, 
2202.6221, 1082.2269, 2202.7104, 1088.4033, 2202.7987, 1088.4915, 
2202.8869, 1088.5798, 2202.9752, 1094.7562, 2209.1516, 1094.8445, 
2209.2399, 1094.9327, 2209.3281, 1095.021, 2215.5045, 1095.1093, 
2215.5928, 1101.2857, 2221.7692, 1101.3739, 2221.8575, 1101.4622, 
2221.9457, 1101.5505, 2222.034, 1107.7269, 2222.1223, 1107.8151, 
2228.2987, 1107.9034, 2228.3869, 1107.9917, 2228.4752, 1114.1681, 
2234.6516, 1114.2563, 2234.7399, 1114.3446, 2234.8281, 1114.4329, 
2234.9163, 1114.5211, 2235.0047, 1114.6094, 2241.1811, 1120.7858, 
2241.2692, 1120.874, 2241.3576, 1120.9623, 2247.534, 1121.0506, 
2247.6223, 1127.227, 2247.7105, 1127.3153, 2247.7988, 1127.4035, 
2253.9752, 1127.4918, 2254.0635, 1127.58, 2254.1517, 1127.6683, 
2254.24, 1127.7566, 2260.4163, 1133.933, 2260.5047, 1134.0212, 
2260.5929, 1134.1095, 2266.7692, 1140.2859, 2266.8576, 1140.3742, 
2266.9459, 1140.4624, 2267.0341, 1140.5507, 2273.2105, 1140.639, 
2273.2988, 1140.7271, 2273.3871, 1140.8155, 2273.4753, 1146.9919, 
2273.5636, 1147.0802, 2279.74, 1147.1684, 2279.8283, 1147.2567, 
2279.9165, 1147.345, 1153.5213, 1153.6096, 1153.6979, 1153.7862, 
1159.9626, 1160.0508, 1160.1391, 1160.2274, 1160.3155, 1160.4039, 
1160.4922, 1166.6686, 1166.7568, 1166.8451), y = c(3.2326, 3.2334, 
3.2342, 3.2349, 3.2358, 3.2366, 3.2374, 3.2382, 3.2389, 3.2398, 
3.2406, 3.2414, 3.2422, 3.2429, 3.2438, 3.2446, 3.2454, 3.2462, 
3.2604, 3.2612, 3.262, 3.2628, 3.2636, 3.2644, 3.2652, 3.266, 
3.2668, 3.2676, 3.2684, 3.2692, 3.2701, 3.2709, 3.2717, 3.2725, 
3.2732, 3.2741, 3.2749, 3.2757, 3.2765, 3.2772, 3.2781, 3.2789, 
3.2797, 3.2805, 3.2812, 3.2821, 3.2829, 3.2837, 3.2845, 3.2852, 
3.2861, 3.2869, 3.2877, 3.2885, 3.2893, 3.2901, 3.2909, 3.2917, 
3.2925, 3.3003, 3.3011, 3.3019, 3.3027, 3.3035, 3.3043, 3.3051, 
3.3059, 3.3067, 3.3075, 3.3083, 3.3091, 3.3099, 3.3107, 3.3115, 
3.3123, 3.3131, 3.3139, 3.3147, 3.3155, 3.3163, 3.3171, 3.3179, 
3.3187, 3.3195, 3.3203, 3.3482, 3.349, 3.3498, 3.3506, 3.3514, 
3.3522, 3.353, 3.3538, 3.3546, 3.3554, 3.3562, 3.357, 3.3578, 
3.3586, 3.3594, 3.3602, 3.3992, 3.4, 3.4008, 3.4016, 3.4024, 
3.4032, 3.404, 3.4048, 3.4056, 3.4064, 3.4072, 3.408, 3.4282, 
3.4471, 3.4479, 3.4487, 3.4495, 3.4503, 3.4511, 3.4519, 3.4527, 
3.4535, 3.4543, 3.4551, 3.4559, 3.4567, 3.4575, 3.4583, 3.4591, 
3.4889, 3.499, 3.4998, 3.5006, 3.5013, 3.5022, 3.503, 3.5038, 
3.5046, 3.5053, 3.5062, 3.507, 3.5488, 3.5495, 3.5525, 3.5533, 
3.5541, 3.5549, 3.5556, 3.5565, 3.5573, 3.5581, 3.5589, 3.6067, 
3.6075, 3.6082, 3.6091, 3.6095, 3.6099, 3.6107, 3.6115, 3.6122, 
3.6602, 3.661, 3.6618, 3.6625, 3.6634, 3.6642, 3.665, 3.6658, 
3.6665, 3.6693, 3.7161, 3.7168, 3.7177, 3.7185, 3.7193, 3.7201, 
3.73, 3.7719, 3.7727, 3.7734, 3.7743, 3.7751, 3.7759, 3.7899, 
3.8262, 3.827, 3.827, 3.8277, 3.8286, 3.8294, 3.8302, 3.831, 
3.8317, 3.8506, 3.882, 3.8829, 3.8837, 3.8845, 3.8853, 3.886, 
3.886, 3.8869, 3.8869, 3.9104, 3.938, 3.9388, 3.9396, 3.9404, 
3.9412, 3.942, 3.946, 3.971, 3.9946, 3.9954, 3.9962, 3.9969, 
3.9978, 4.0066, 4.031, 4.0521, 4.0529, 4.0537, 4.0545, 4.0665, 
4.0909, 4.1088, 4.1096, 4.1104, 4.1112, 4.112, 4.1264, 4.1507, 
4.1663, 4.1671, 4.1679, 4.1687, 4.1863, 4.2114, 4.2213, 4.2221, 
4.2229, 4.2237, 4.2245, 4.2253, 4.2261, 4.2461, 4.2721, 4.3068, 
4.332, 4.3667, 4.3926, 4.4274, 4.4525, 4.4872, 4.5124, 4.5471, 
4.5731, 4.607, 4.6329, 4.6669, 4.6936, 4.7276, 4.7534, 4.7873, 
4.8134, 4.8473, 4.874, 4.908, 4.9339, 4.9679, 4.9938, 5.0277, 
5.0545, 5.0884, 5.1144, 5.1482, 5.1742, 5.175, 5.2082, 5.2341, 
5.2688, 5.2948, 5.3287, 5.3547, 5.3886, 5.4144, 5.4153, 5.4493, 
5.4744, 5.5091, 5.5351, 5.569, 5.595, 5.6289, 5.6548, 5.6556, 
5.6896, 5.7155, 5.7494, 5.7753, 5.8101, 5.8353, 5.87, 5.8951, 
5.8959, 5.9299, 5.9558, 5.9897, 6.0157, 6.0504, 6.0756, 6.1111, 
6.1354, 6.1362, 6.171, 6.1961, 6.2308, 6.256, 6.2907, 6.3159, 
6.3514, 6.3757, 6.3765, 6.4113, 6.4364, 6.472, 6.4963, 6.5326, 
6.5562, 6.5925, 6.6168, 6.6524, 6.6766, 6.713, 6.7366, 6.7729, 
6.7973, 6.8328, 6.8572, 6.8935, 6.9178, 6.9534, 6.9777, 7.014, 
7.0376, 7.0747, 7.0983, 7.1346, 7.1581, 7.1945, 7.218, 7.2551, 
7.2787, 7.315, 7.3386, 7.3757, 7.3992, 7.4356, 7.4591, 7.4954, 
7.519, 7.5561, 7.5796, 7.6168, 7.6395, 7.6766, 7.7002, 7.7365, 
7.7601, 7.7972, 7.8199, 7.8571, 7.8806, 7.9178, 7.9413, 7.9776, 
7.9784, 8.0012, 8.0383, 8.0611, 8.0982, 8.1217, 8.1589, 8.1816, 
8.2187, 8.2196, 8.2423, 8.2793, 8.3022, 8.3393, 8.362, 8.4, 8.4227, 
8.4599, 8.4607, 8.4834, 8.5205, 8.5433, 8.5804, 8.6032, 8.6411, 
8.6638, 8.701, 8.7245, 8.7608, 8.7844, 8.8215, 8.8451, 8.8822, 
8.9049, 8.9421, 8.9428, 8.9656, 9.0027, 9.0255, 9.0626, 9.0862, 
9.1233, 9.146, 9.1832, 9.2067, 9.2438, 9.2666, 9.3045, 9.3273, 
9.3644, 9.3879, 9.4243, 9.4478, 9.4849, 9.5077, 9.5455, 9.5684, 
9.6055, 9.6063, 9.629, 9.6662, 9.6888, 9.726, 9.7496, 9.7867, 
9.8094, 9.8474, 9.87, 9.9073, 9.93, 9.968, 9.9907, 10.0278, 10.0514, 
10.0877, 10.1112, 10.1484, 10.1711, 10.2091, 10.2318, 10.2689, 
10.2697, 10.2925, 10.3296, 10.3524, 10.3895, 10.413, 10.4502, 
10.4737, 10.51, 10.5335, 10.5707, 10.5943, 10.6314, 10.6549, 
10.6913, 10.7147, 10.7519, 10.7755, 10.8126, 10.8354, 10.8725, 
10.896, 10.9332, 10.9559, 10.9929, 11.0166, 11.0537, 11.0773, 
11.1136, 11.1371, 11.1743, 11.1978, 11.2349, 11.2585, 11.2948, 
11.2955, 11.3184, 11.3555, 11.379, 11.4154, 11.4397, 11.4761, 
11.4996, 11.5367, 11.5603, 11.5966, 11.6209, 11.6573, 11.6808, 
11.7172, 11.7415, 11.7778, 11.8014, 11.8385, 11.862, 11.8984, 
11.9226, 11.959, 11.9826, 12.0197, 12.0433, 12.0796, 12.104, 
12.1403, 12.1638, 12.201, 12.2245, 12.2608, 12.2852, 12.3215, 
12.3451, 12.3822, 12.4057, 12.4421, 12.4664, 12.5027, 12.5263, 
12.5634, 12.587, 12.6233, 12.6476, 12.684, 12.7075, 12.7438, 
12.7682, 12.8045, 12.8289, 12.8652, 12.8887, 12.9251, 12.9494, 
12.9858, 13.0101, 13.0464, 13.0708, 13.1071, 13.1306, 13.167, 
13.1913, 13.2277, 13.2511, 13.2883, 13.3119, 13.3482, 13.3726, 
13.4089, 13.4324, 13.4687, 13.4931, 13.5293, 13.5537, 13.5901, 
13.6145, 13.65, 13.6751, 13.7107, 13.7349, 13.7713, 13.7957, 
13.8312, 13.8564, 13.8919, 13.9162, 13.9526, 13.9769, 14.0124, 
14.0376, 14.0731, 14.0983, 14.1338, 14.1581, 14.1945, 14.2187, 
14.2543, 14.2795, 14.315, 14.3394, 14.3757, 14.4, 14.4356, 14.4607, 
14.4963, 14.5213, 14.5569, 14.5813, 14.6168, 14.642, 14.6775, 
14.7026, 14.7382, 14.7633, 14.7988, 14.8232, 14.8587, 14.8839, 
14.9194, 14.9445, 14.9801, 15.0044, 15.0399, 15.0651, 15.1006, 
15.1258, 15.1613, 15.1864, 15.2212, 15.2471, 15.2818, 15.307, 
15.3425, 15.3677, 15.4032, 15.4283, 15.4639, 15.4882, 15.5237, 
15.5489, 15.5844, 15.6096, 15.6451, 15.6702, 15.705, 15.7309, 
15.7657, 15.7908, 15.8255, 15.8515, 15.8862, 15.9121, 15.9468, 
15.9727, 16.0076, 16.0327, 16.0682, 16.0934, 16.128, 16.1541, 
16.1888, 16.2147, 16.2495, 16.2746, 16.3093, 16.3353, 16.37, 
16.396, 16.4307, 16.4566, 16.4914, 16.5173, 16.552, 16.5779, 
16.6118, 16.6379, 16.6726, 16.6985, 16.7332, 16.7591, 16.7931, 
16.8199, 16.8538, 16.8798, 16.9144, 16.9404, 16.9752, 17.0011, 
17.035, 17.0618, 17.0957, 17.1225, 17.1564, 17.1831, 17.2171, 
17.2438, 17.277, 17.3037, 17.3376, 17.3644, 17.3982, 17.425, 
17.4582, 17.4849, 17.5189, 17.5455, 17.5795, 17.6063, 17.6402, 
17.667, 17.7001, 17.7276, 17.7608, 17.7883, 17.8214, 17.849, 
17.882, 17.9089, 17.9428, 17.9695, 18.0027, 18.0302, 18.0633, 
18.0909, 18.124, 18.1516, 18.2114, 18.2721, 18.3328, 18.3935, 
18.4533, 18.514, 18.5747, 18.6354, 18.696, 18.7567, 18.8174, 
18.8773, 18.938, 18.9986)), .Names = c("x", "y"), class = "data.frame", row.names = c(NA, 
-736L))

1 个答案:

答案 0 :(得分:1)

为了防止这对任何人都有用,我能够使用geom_path()解决问题,首先手动重新排列我的数据,以便跟踪数据的连接路径。我不得不做一些回溯等路径,但能够做到这一点。我希望有一个更好的解决方案(如果有,请告诉我),但我能够在此期间得到这个解决方法。