如何根据ggplot中的变量控制行中的行大小?

问题描述 投票:0回答:3

我一直在拼命地寻找解决方案几个小时,但没有任何效果。分组值应与geom_line一起显示,并且在每行中,我要使用变量= 0.4或0.6来控制行的大小。仅创建此丑陋的图形:如果我曾经使用geom_segment进行绘制,它将起作用,但是我不希望这样,也不会出现全面的图例。有人知道解决方案吗?

id<-c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
      2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
      3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
      3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 
      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 
      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5)
x<-c(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, 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, 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, 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, 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)
y<-c(930, 880, 850, 870, 775, 810, 840, 900, 880, 860, 864.985549012236, 
     870, 870, 890, 874.871419123976, 860, 880, 875, 870, 879.943179983799, 
     890, 941.036662410131, 995, 1020, 990, 1048.28431257937, 1110, 
     1020, 1025, 1030, 1020, 1060, 1075, 1080, 1089.9541274751, 1100, 
     1115, 1150, 1155, 1180, 1210, 1235, 1265, 1305, 1351.66563912826, 
     1400, 1480, 1524.3359209833, 1570, 1624.06896405294, 1680, 1714.64281994822, 
     1750, 1754.99287747842, 1760, 1765, 1797.20616513521, 1830, 1856.28725225379, 
     1882.95211086335, 1910, 1983.58261738703, 2060, 2069.9758452697, 
     2080, 2114.71038206181, 2150, 2155, 2182.32673997273, 2210, 2220, 
     2250, 2318.94372506105, 2390, 2370, 725, 702.651508377929, 680.991920311418, 
     660, 660, 640, 655, 605, 640, 670, 675, 690, 705, 715, 725, 750, 
     750, 800, 800, 840, 840, 870, 889.775252521669, 910, 934.665715643834, 
     960, 991.96774141098, 1025, 1042.35310715707, 1060, 1084.71194332873, 
     1110, 1129.82299498638, 1150, 1160, 1240, 1274.51951730839, 1310, 
     1350, 1360, 1409.11319630468, 1460, 1504.32709209134, 1550, 1594.36507738974, 
     1640, 1684.39900261191, 1730, 1767.51398577974, 1805.84143926415, 
     1845, 1906.4758062981, 1970, 1984.94332412792, 2000, 2000, 2000, 
     2059.1260281974, 2120, 2203.36106891267, 2290, 2330, 2365, 2360, 
     2410, 2440, 2440, 2500, 2509.98007960223, 2520, 2524.9950495001, 
     2530, 2555, 1090, 995, 975, 965, 985, 965, 980, 1015, 1040, 1080, 
     1090, 1120, 1140, 1160, 1155, 1160, 1190, 1190, 1194.98953970317, 
     1200, 1190, 1230, 1288.60389569487, 1350, 1370, 1390, 1430, 1470, 
     1464.99146755194, 1460, 1560, 1564.99201275917, 1570, 1648.05946494658, 
     1730, 1745, 1730, 1759.74429960719, 1790, 1800, 1845.5065038092, 
     1892.16347533448, 1940, 1969.77156035922, 2000, 2020, 2032.46156175215, 
     2045, 2057.46202881122, 2070, 2148.51111237527, 2230, 2280, 2300, 
     2330, 2340, 815, 835, 827.46601138657, 820, 760, 770, 760, 800, 
     824.621125123532, 850, 850, 903.327183250897, 960, 940, 960, 
     972.419662491458, 985, 1016.98082577795, 1050, 1074.70926301023, 
     1100, 1104.9886877249, 1110, 1132.27646800594, 1155, 1190, 1220, 
     1250, 1264.91106406735, 1280, 1294.91312449909, 1310, 1346.97809930229, 
     1385, 1410, 1437.2369324506, 1465, 1474.96610130538, 1485, 1550, 
     1590, 1590, 1641.17640733713, 1694, 1698.99264271509, 1704, 1718.93455372798, 
     1734, 1805, 1819.93818576346, 1835, 1850, 1928.34125610588, 2010, 
     2020, 2093.65708749069, 2170, 2149.9069747317, 2130, 2174.53443293041, 
     2220, 2252.84499374776, 2286.17593056501, 2320, 980, 910, 940, 
     950, 950, 960, 965, 1005, 1005, 1035, 1045, 1110, 1124.89999555516, 
     1140, 1165, 1170, 1200, 1235, 1265, 1300, 1360, 1384.7743498491, 
     1410, 1439.68746608422, 1470, 1490, 1499.96666629629, 1510, 1560, 
     1575, 1590, 1629.50912854148, 1670, 1694.81562419043, 1720, 1860, 
     1860, 1860, 1860, 1884.83421021585, 1910, 1940, 1970)
ms<-c(0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 
      0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 
      0.6, 0.6, 0.6, 0.4, 0.4, 0.4, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 
      0.6, 0.6, 0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 
      0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0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0.4, 
      0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 
      0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 
      0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 
      0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4)
Dfa<-data.frame(id=id,x=x,y=y,ms=ms)
g<-ggplot(data=Dfa,aes(x,y,group=id,size=as.numeric(ms)))
g+geom_line()

enter image description here

r ggplot2 size line
3个回答
0
投票

您是否正在寻找类似的东西?


0
投票

感谢您的回答,不,我想像在mc中那样精确地控制行的大小0.4和0.6。这些部分之间的关​​系为假。


0
投票

我想在0.4和0.6之间有确切的关系,而不是很胖的部分。

© www.soinside.com 2019 - 2024. All rights reserved.