我遇到的问题是ggplot2正在使用我的因子变量的标签并按字母顺序排序:而不是常规的1,2,3,...,19,20,它是1,10,11 ,. ..,8,9。那些标签值是按数字排序的,所以我想保留它们的数字顺序。有趣的是,ggplot2并没有改变我所有情节的顺序,但我无法确定原因。
这是我的例子(重新排序因子):
#Dataframes with my data
df1<-structure(list(var = structure(c(13L, 21L, 14L, 20L, 15L, 19L,
15L, 19L, 14L, 21L, 19L, 21L, 21L, 18L, 19L, 21L, 19L, 14L, 21L,
21L, 18L, 18L, 16L, 19L, 19L, 15L, 21L, 21L, 20L, 12L, 20L, 13L,
20L, 14L, 19L, 14L, 18L, 13L, 21L, 18L, 20L, 21L, 16L, 19L, 21L,
19L, 14L, 21L, 21L, 16L, 17L, 15L, 19L, 18L, 14L, 21L, 21L, 20L,
10L, 19L, 9L, 18L, 9L, 17L, 10L, 13L, 9L, 19L, 14L, 18L, 19L,
12L, 15L, 21L, 15L, 11L, 20L, 19L, 10L, 13L, 13L, 15L, 15L, 13L,
21L, 21L, 18L, 15L, 21L, 14L, 21L, 15L, 20L, 16L, 18L, 15L, 21L,
19L, 21L, 21L, 17L, 19L, 21L, 19L, 16L, 21L, 21L, 15L, 18L, 18L,
19L, 19L, 18L, 21L, 21L, 21L, 12L, 20L, 14L, 20L, 15L, 21L, 16L,
21L, 16L, 21L, 18L, 21L, 21L, 16L, 19L, 21L, 20L, 17L, 21L, 21L,
16L, 18L, 17L, 20L, 20L, 17L, 21L, 21L, 21L, 21L, 14L, 21L, 16L,
21L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22"), class = "factor"), mod = c(1.00085320097232, 0.983799236755741,
0.999021834640581, 0.985966169712423, 0.997517466666048, 0.989925820179825,
0.997690971078398, 0.990613583427106, 0.999269305935753, 0.984733380794849,
0.990776002248053, 0.984571728046385, 0.981286505772827, 0.992668559258466,
0.98882425989506, 0.980020311111573, 0.988802790209461, 0.999092759197013,
0.983769390705821, 0.983079755458444, 0.992881959366547, 0.992490394137259,
0.995220587055765, 0.989352556519739, 0.991050300097109, 0.997890240400418,
0.973313759690094, 0.976272073418161, 0.987027958906971, 1.0027659361555,
0.985726733528214, 1.00138595619949, 0.988000713704551, 0.999529568889752,
0.990497982605707, 0.999028886979944, 0.992719213547987, 1.00041521639887,
0.984643439115305, 0.992063383679324, 0.986103466394401, 0.98266800360026,
0.994918877843687, 0.990948196101149, 0.980983356931702, 0.990847404545752,
0.999974270713516, 0.984913756799606, 0.984404797639798, 0.996263406321717,
0.99408186608625, 0.996796935957794, 0.990534807040301, 0.992372803345729,
0.99900673620916, 0.975336985470914, 0.977148682610603, 0.987880477729105,
1.00590649163168, 0.989771514776825, 1.00780619287412, 0.991586859129135,
1.0071417052493, 0.994233066700575, 1.0047918709384, 1.00053113909975,
1.0066746000826, 0.989278460343596, 0.998753654081146, 0.991816067103673,
0.990690375727478, 1.00211962621255, 0.998150543715061, 0.984751882887788,
0.997386898093705, 1.00361468274586, 0.988322918041743, 0.988810477257792,
1.00594541898852, 1.00096785177224, 1.00080296512135, 0.996934910462889,
0.996878827147476, 1.00029065201754, 0.978503193342591, 0.980703643525914,
0.992105333717596, 0.998282717437973, 0.982872351917007, 0.998809487332376,
0.984115879655268, 0.997838360290591, 0.987231298924994, 0.996010019868602,
0.992048256844709, 0.998259498113374, 0.982773883437325, 0.990268824715062,
0.984508117312714, 0.983729503750958, 0.99360208564058, 0.98999861372894,
0.978059879420204, 0.989081253502619, 0.995652587554496, 0.981280875901191,
0.981623777643685, 0.996721335719507, 0.992497882676074, 0.993046421047081,
0.988755919954368, 0.989232458005766, 0.992937858352865, 0.972547543124041,
0.974619875850771, 0.985382561699533, 1.00240625434892, 0.985828223388321,
0.999815368367156, 0.98646588341636, 0.997025863464747, 0.98553712475649,
0.99550537100776, 0.985185290197646, 0.994959310107694, 0.980529854063247,
0.992481393265307, 0.984536389883072, 0.985070705355204, 0.9949514147155,
0.991077687690396, 0.980414970228045, 0.98723517731121, 0.994066429479647,
0.983135643243082, 0.982822586214233, 0.995451451368164, 0.99312465978728,
0.993827129587088, 0.985846032126488, 0.986318914894866, 0.994164797628927,
0.974434055919853, 0.973229511503257, 0.983681222736799, 0.97490232753215,
0.998489782359852, 0.983492094660751, 0.995942503398888, 0.982502348464547
), low = c(1.00008962426941, 0.973856897337124, 0.998493699796719,
0.985752014137461, 0.996817199922311, 0.988851347545285, 0.996817199922311,
0.988851347545285, 0.998493699796719, 0.973856897337124, 0.988851347545285,
0.973856897337124, 0.973856897337124, 0.99148788682308, 0.988851347545285,
0.973856897337124, 0.988851347545285, 0.998493699796719, 0.973856897337124,
0.973856897337124, 0.99148788682308, 0.99148788682308, 0.994925479951989,
0.988851347545285, 0.988851347545285, 0.996817199922311, 0.973856897337124,
0.973856897337124, 0.985752014137461, 1.00165033860141, 0.985752014137461,
1.00008962426941, 0.985752014137461, 0.998493699796719, 0.988851347545285,
0.998493699796719, 0.99148788682308, 1.00008962426941, 0.973856897337124,
0.99148788682308, 0.985752014137461, 0.973856897337124, 0.994925479951989,
0.988851347545285, 0.973856897337124, 0.988851347545285, 0.998493699796719,
0.973856897337124, 0.973856897337124, 0.994925479951989, 0.993252734657271,
0.996817199922311, 0.988851347545285, 0.99148788682308, 0.998493699796719,
0.973856897337124, 0.973856897337124, 0.985752014137461, 1.00468196577565,
0.988851347545285, 1.00639609166503, 0.99148788682308, 1.00639609166503,
0.993252734657271, 1.00468196577565, 1.00008962426941, 1.00639609166503,
0.988851347545285, 0.998493699796719, 0.99148788682308, 0.988851347545285,
1.00165033860141, 0.996817199922311, 0.973856897337124, 0.996817199922311,
1.00305217148501, 0.985752014137461, 0.988851347545285, 1.00468196577565,
1.00008962426941, 1.00008962426941, 0.996817199922311, 0.996817199922311,
1.00008962426941, 0.973856897337124, 0.973856897337124, 0.99148788682308,
0.996817199922311, 0.973856897337124, 0.998493699796719, 0.973856897337124,
0.996817199922311, 0.985752014137461, 0.994925479951989, 0.99148788682308,
0.996817199922311, 0.973856897337124, 0.988851347545285, 0.973856897337124,
0.973856897337124, 0.993252734657271, 0.988851347545285, 0.973856897337124,
0.988851347545285, 0.994925479951989, 0.973856897337124, 0.973856897337124,
0.996817199922311, 0.99148788682308, 0.99148788682308, 0.988851347545285,
0.988851347545285, 0.99148788682308, 0.973856897337124, 0.973856897337124,
0.973856897337124, 1.00165033860141, 0.985752014137461, 0.998493699796719,
0.985752014137461, 0.996817199922311, 0.973856897337124, 0.994925479951989,
0.973856897337124, 0.994925479951989, 0.973856897337124, 0.99148788682308,
0.973856897337124, 0.973856897337124, 0.994925479951989, 0.988851347545285,
0.973856897337124, 0.985752014137461, 0.993252734657271, 0.973856897337124,
0.973856897337124, 0.994925479951989, 0.99148788682308, 0.993252734657271,
0.985752014137461, 0.985752014137461, 0.993252734657271, 0.973856897337124,
0.973856897337124, 0.973856897337124, 0.973856897337124, 0.998493699796719,
0.973856897337124, 0.994925479951989, 0.973856897337124), high = c(1.00148023477861,
0.985302892335616, 0.999913842511162, 0.98849687390284, 0.998355355424634,
0.991266639058593, 0.998355355424634, 0.991266639058593, 0.999913842511162,
0.985302892335616, 0.991266639058593, 0.985302892335616, 0.985302892335616,
0.993099642276173, 0.991266639058593, 0.985302892335616, 0.991266639058593,
0.999913842511162, 0.985302892335616, 0.985302892335616, 0.993099642276173,
0.993099642276173, 0.996587804927349, 0.991266639058593, 0.991266639058593,
0.998355355424634, 0.985302892335616, 0.985302892335616, 0.98849687390284,
1.00289415242267, 0.98849687390284, 1.00148023477861, 0.98849687390284,
0.999913842511162, 0.991266639058593, 0.999913842511162, 0.993099642276173,
1.00148023477861, 0.985302892335616, 0.993099642276173, 0.98849687390284,
0.985302892335616, 0.996587804927349, 0.991266639058593, 0.985302892335616,
0.991266639058593, 0.999913842511162, 0.985302892335616, 0.985302892335616,
0.996587804927349, 0.994701266808039, 0.998355355424634, 0.991266639058593,
0.993099642276173, 0.999913842511162, 0.985302892335616, 0.985302892335616,
0.98849687390284, 1.00621846681864, 0.991266639058593, 1.00792911808258,
0.993099642276173, 1.00792911808258, 0.994701266808039, 1.00621846681864,
1.00148023477861, 1.00792911808258, 0.991266639058593, 0.999913842511162,
0.993099642276173, 0.991266639058593, 1.00289415242267, 0.998355355424634,
0.985302892335616, 0.998355355424634, 1.00448351173732, 0.98849687390284,
0.991266639058593, 1.00621846681864, 1.00148023477861, 1.00148023477861,
0.998355355424634, 0.998355355424634, 1.00148023477861, 0.985302892335616,
0.985302892335616, 0.993099642276173, 0.998355355424634, 0.985302892335616,
0.999913842511162, 0.985302892335616, 0.998355355424634, 0.98849687390284,
0.996587804927349, 0.993099642276173, 0.998355355424634, 0.985302892335616,
0.991266639058593, 0.985302892335616, 0.985302892335616, 0.994701266808039,
0.991266639058593, 0.985302892335616, 0.991266639058593, 0.996587804927349,
0.985302892335616, 0.985302892335616, 0.998355355424634, 0.993099642276173,
0.993099642276173, 0.991266639058593, 0.991266639058593, 0.993099642276173,
0.985302892335616, 0.985302892335616, 0.985302892335616, 1.00289415242267,
0.98849687390284, 0.999913842511162, 0.98849687390284, 0.998355355424634,
0.985302892335616, 0.996587804927349, 0.985302892335616, 0.996587804927349,
0.985302892335616, 0.993099642276173, 0.985302892335616, 0.985302892335616,
0.996587804927349, 0.991266639058593, 0.985302892335616, 0.98849687390284,
0.994701266808039, 0.985302892335616, 0.985302892335616, 0.996587804927349,
0.993099642276173, 0.994701266808039, 0.98849687390284, 0.98849687390284,
0.994701266808039, 0.985302892335616, 0.985302892335616, 0.985302892335616,
0.985302892335616, 0.999913842511162, 0.985302892335616, 0.996587804927349,
0.985302892335616), var_ori = structure(c(13L, 21L, 14L, 20L,
15L, 19L, 15L, 19L, 14L, 21L, 19L, 21L, 21L, 18L, 19L, 21L, 19L,
14L, 21L, 21L, 18L, 18L, 16L, 19L, 19L, 15L, 21L, 21L, 20L, 12L,
20L, 13L, 20L, 14L, 19L, 14L, 18L, 13L, 21L, 18L, 20L, 21L, 16L,
19L, 21L, 19L, 14L, 21L, 21L, 16L, 17L, 15L, 19L, 18L, 14L, 21L,
21L, 20L, 10L, 19L, 9L, 18L, 9L, 17L, 10L, 13L, 9L, 19L, 14L,
18L, 19L, 12L, 15L, 21L, 15L, 11L, 20L, 19L, 10L, 13L, 13L, 15L,
15L, 13L, 21L, 21L, 18L, 15L, 21L, 14L, 21L, 15L, 20L, 16L, 18L,
15L, 21L, 19L, 21L, 21L, 17L, 19L, 21L, 19L, 16L, 21L, 21L, 15L,
18L, 18L, 19L, 19L, 18L, 21L, 21L, 21L, 12L, 20L, 14L, 20L, 15L,
21L, 16L, 21L, 16L, 21L, 18L, 21L, 21L, 16L, 19L, 21L, 20L, 17L,
21L, 21L, 16L, 18L, 17L, 20L, 20L, 17L, 21L, 21L, 21L, 21L, 14L,
21L, 16L, 21L), .Label = c("0.86", "[1.15,3.11)", "[3.11,3.47)",
"[3.47,3.77)", "[3.77,4.02)", "[4.02,4.21)", "[4.21,4.41)", "[4.41,4.57)",
"[4.57,4.75)", "[4.75,4.93)", "[4.93,5.09)", "[5.09,5.24)", "[5.24,5.41)",
"[5.41,5.58)", "[5.58,5.77)", "[5.77,5.98)", "[5.98,6.17)", "[6.17,6.38)",
"[6.38,6.70)", "[6.70,7.08)", "[7.08,9.28)", "[9.28,9.54]"), class = "factor")), .Names = c("var",
"mod", "low", "high", "var_ori"), row.names = c(NA, 150L), class = "data.frame")
df2<-structure(list(var = structure(c(11L, 19L, 10L, 19L, 10L, 18L,
12L, 14L, 10L, 19L, 15L, 18L, 19L, 13L, 16L, 20L, 16L, 12L, 20L,
19L, 11L, 14L, 14L, 16L, 16L, 14L, 20L, 20L, 18L, 10L, 19L, 12L,
19L, 14L, 19L, 15L, 19L, 14L, 20L, 17L, 20L, 19L, 15L, 18L, 20L,
19L, 16L, 20L, 20L, 14L, 15L, 16L, 19L, 18L, 14L, 20L, 20L, 19L,
20L, 11L, 19L, 13L, 19L, 14L, 20L, 15L, 20L, 16L, 20L, 17L, 20L,
20L, 16L, 18L, 20L, 19L, 16L, 20L, 20L, 15L, 17L, 16L, 20L, 19L,
16L, 20L, 20L, 20L, 20L, 11L, 19L, 12L, 19L, 13L, 19L, 14L, 20L,
14L, 20L, 16L, 20L, 19L, 14L, 16L, 20L, 18L, 15L, 20L, 19L, 14L,
15L, 15L, 19L, 18L, 15L, 20L, 20L, 19L, 20L, 9L, 19L, 12L, 18L,
12L, 19L, 13L, 19L, 13L, 20L, 15L, 19L, 18L, 13L, 15L, 20L, 18L,
14L, 19L, 19L, 13L, 14L, 14L, 18L, 18L, 13L, 20L, 20L, 18L, 20L,
2L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"
), class = "factor"), mod = c(0.999776431730114, 0.986727662740201,
1.00023630560784, 0.989171891730747, 1.00009434915076, 0.992232386050353,
0.999468360916685, 0.997484810397401, 1.0000242641676, 0.985835480467107,
0.996395671266124, 0.989568711931697, 0.98797231320128, 0.998383497318398,
0.995852026211342, 0.978199451029572, 0.995277924515125, 0.999060954379668,
0.98447913810294, 0.985193141484994, 0.999828711660704, 0.997727027911407,
0.997636253551257, 0.994971350397964, 0.994866886453903, 0.997522933684193,
0.963863040667508, 0.969512816146659, 0.989939681720488, 1.00020365455916,
0.986150964091569, 0.999116164627643, 0.987392959468332, 0.998190851966455,
0.988490528069752, 0.997167366641329, 0.98672574005535, 0.997418868029662,
0.976032948557903, 0.993239873949519, 0.984875316545771, 0.985429920362902,
0.996068676789879, 0.992216868519829, 0.976403464232568, 0.98698177476738,
0.995120083679956, 0.981855635405889, 0.983433650250075, 0.997392558818255,
0.996122313122368, 0.995273755399623, 0.98777563018575, 0.990591312786413,
0.997233224721132, 0.964659274811211, 0.960231139418912, 0.988393148627114,
0.966201379766396, 0.999750797367541, 0.985079357898489, 0.99873029740055,
0.985837046076991, 0.997307855657763, 0.98460772946944, 0.996178620866654,
0.983665621115944, 0.995727313711604, 0.974758009167725, 0.993582444777839,
0.982739005059511, 0.983628917548309, 0.995739913209549, 0.992022304088441,
0.974515090030568, 0.987087288794565, 0.995003570881205, 0.980159493575185,
0.979617658658512, 0.996179921589942, 0.994122761079012, 0.994753741238143,
0.984869174548967, 0.98589230974564, 0.995189703304288, 0.959289949527194,
0.955987653881928, 0.982685774130364, 0.961014411592437, 0.999732517183056,
0.986337128524806, 0.999211772799094, 0.988809952792023, 0.998352328778159,
0.988831932651434, 0.997441689661469, 0.98441032959034, 0.997877910557652,
0.97722737404137, 0.994640918160321, 0.984096656227718, 0.988961430670896,
0.998257322516557, 0.99567346076362, 0.984117074088852, 0.989803848655887,
0.996389604288659, 0.982814172218141, 0.985210306292689, 0.997968260095857,
0.996355602688329, 0.996840299318173, 0.98836202594914, 0.989510973501589,
0.996715217048015, 0.95906172894744, 0.952300547761713, 0.98531967559576,
0.963626819114621, 1.00040336526581, 0.987897539590952, 0.999245662827765,
0.990612915734394, 0.999307786957358, 0.989096279548965, 0.998860996127054,
0.988260217915671, 0.998825981238456, 0.982488720347447, 0.996847841884664,
0.987551240848546, 0.989763617193185, 0.998761846507044, 0.996405919362226,
0.984010764066075, 0.991766155385054, 0.997972236867794, 0.986482203358589,
0.985929893190579, 0.998624759552253, 0.997721230882173, 0.997903330728556,
0.990613258105199, 0.9912262231538, 0.998718980682088, 0.971295852761292,
0.966483279298645, 0.99070318552007, 0.97126608277427, 0.99454864691887
), low = c(0.99962264333467, 0.985207731571535, 1.00002427886981,
0.985207731571535, 1.00002427886981, 0.989849772581204, 0.999056092772957,
0.997306703342966, 1.00002427886981, 0.985207731571535, 0.996018377275769,
0.989849772581204, 0.985207731571535, 0.998307553959348, 0.994557546712157,
0.959634718409053, 0.994557546712157, 0.999056092772957, 0.959634718409053,
0.985207731571535, 0.99962264333467, 0.997306703342966, 0.997306703342966,
0.994557546712157, 0.994557546712157, 0.997306703342966, 0.959634718409053,
0.959634718409053, 0.989849772581204, 1.00002427886981, 0.985207731571535,
0.999056092772957, 0.985207731571535, 0.997306703342966, 0.985207731571535,
0.996018377275769, 0.985207731571535, 0.997306703342966, 0.959634718409053,
0.992793233455545, 0.959634718409053, 0.985207731571535, 0.996018377275769,
0.989849772581204, 0.959634718409053, 0.985207731571535, 0.994557546712157,
0.959634718409053, 0.959634718409053, 0.997306703342966, 0.996018377275769,
0.994557546712157, 0.985207731571535, 0.989849772581204, 0.997306703342966,
0.959634718409053, 0.959634718409053, 0.985207731571535, 0.959634718409053,
0.99962264333467, 0.985207731571535, 0.998307553959348, 0.985207731571535,
0.997306703342966, 0.959634718409053, 0.996018377275769, 0.959634718409053,
0.994557546712157, 0.959634718409053, 0.992793233455545, 0.959634718409053,
0.959634718409053, 0.994557546712157, 0.989849772581204, 0.959634718409053,
0.985207731571535, 0.994557546712157, 0.959634718409053, 0.959634718409053,
0.996018377275769, 0.992793233455545, 0.994557546712157, 0.959634718409053,
0.985207731571535, 0.994557546712157, 0.959634718409053, 0.959634718409053,
0.959634718409053, 0.959634718409053, 0.99962264333467, 0.985207731571535,
0.999056092772957, 0.985207731571535, 0.998307553959348, 0.985207731571535,
0.997306703342966, 0.959634718409053, 0.997306703342966, 0.959634718409053,
0.994557546712157, 0.959634718409053, 0.985207731571535, 0.997306703342966,
0.994557546712157, 0.959634718409053, 0.989849772581204, 0.996018377275769,
0.959634718409053, 0.985207731571535, 0.997306703342966, 0.996018377275769,
0.996018377275769, 0.985207731571535, 0.989849772581204, 0.996018377275769,
0.959634718409053, 0.959634718409053, 0.985207731571535, 0.959634718409053,
1.00032142854411, 0.985207731571535, 0.999056092772957, 0.989849772581204,
0.999056092772957, 0.985207731571535, 0.998307553959348, 0.985207731571535,
0.998307553959348, 0.959634718409053, 0.996018377275769, 0.985207731571535,
0.989849772581204, 0.998307553959348, 0.996018377275769, 0.959634718409053,
0.989849772581204, 0.997306703342966, 0.985207731571535, 0.985207731571535,
0.998307553959348, 0.997306703342966, 0.997306703342966, 0.989849772581204,
0.989849772581204, 0.998307553959348, 0.959634718409053, 0.959634718409053,
0.989849772581204, 0.959634718409053, 0.994304341619655), high = c(0.999987725709517,
0.989104505288002, 1.00029004593091, 0.989104505288002, 1.00029004593091,
0.992526041900909, 0.999580726942107, 0.998201677880488, 1.00029004593091,
0.989104505288002, 0.997171743948177, 0.992526041900909, 0.989104505288002,
0.998992364213859, 0.995823926135333, 0.98483423431047, 0.995823926135333,
0.999580726942107, 0.98483423431047, 0.989104505288002, 0.999987725709517,
0.998201677880488, 0.998201677880488, 0.995823926135333, 0.995823926135333,
0.998201677880488, 0.98483423431047, 0.98483423431047, 0.992526041900909,
1.00029004593091, 0.989104505288002, 0.999580726942107, 0.989104505288002,
0.998201677880488, 0.989104505288002, 0.997171743948177, 0.989104505288002,
0.998201677880488, 0.98483423431047, 0.994401182193857, 0.98483423431047,
0.989104505288002, 0.997171743948177, 0.992526041900909, 0.98483423431047,
0.989104505288002, 0.995823926135333, 0.98483423431047, 0.98483423431047,
0.998201677880488, 0.997171743948177, 0.995823926135333, 0.989104505288002,
0.992526041900909, 0.998201677880488, 0.98483423431047, 0.98483423431047,
0.989104505288002, 0.98483423431047, 0.999987725709517, 0.989104505288002,
0.998992364213859, 0.989104505288002, 0.998201677880488, 0.98483423431047,
0.997171743948177, 0.98483423431047, 0.995823926135333, 0.98483423431047,
0.994401182193857, 0.98483423431047, 0.98483423431047, 0.995823926135333,
0.992526041900909, 0.98483423431047, 0.989104505288002, 0.995823926135333,
0.98483423431047, 0.98483423431047, 0.997171743948177, 0.994401182193857,
0.995823926135333, 0.98483423431047, 0.989104505288002, 0.995823926135333,
0.98483423431047, 0.98483423431047, 0.98483423431047, 0.98483423431047,
0.999987725709517, 0.989104505288002, 0.999580726942107, 0.989104505288002,
0.998992364213859, 0.989104505288002, 0.998201677880488, 0.98483423431047,
0.998201677880488, 0.98483423431047, 0.995823926135333, 0.98483423431047,
0.989104505288002, 0.998201677880488, 0.995823926135333, 0.98483423431047,
0.992526041900909, 0.997171743948177, 0.98483423431047, 0.989104505288002,
0.998201677880488, 0.997171743948177, 0.997171743948177, 0.989104505288002,
0.992526041900909, 0.997171743948177, 0.98483423431047, 0.98483423431047,
0.989104505288002, 0.98483423431047, 1.00046097281219, 0.989104505288002,
0.999580726942107, 0.992526041900909, 0.999580726942107, 0.989104505288002,
0.998992364213859, 0.989104505288002, 0.998992364213859, 0.98483423431047,
0.997171743948177, 0.989104505288002, 0.992526041900909, 0.998992364213859,
0.997171743948177, 0.98483423431047, 0.992526041900909, 0.998201677880488,
0.989104505288002, 0.989104505288002, 0.998992364213859, 0.998201677880488,
0.998201677880488, 0.992526041900909, 0.992526041900909, 0.998992364213859,
0.98483423431047, 0.98483423431047, 0.992526041900909, 0.98483423431047,
0.996555288394208), var_ori = structure(c(11L, 19L, 10L, 19L,
10L, 18L, 12L, 14L, 10L, 19L, 15L, 18L, 19L, 13L, 16L, 20L, 16L,
12L, 20L, 19L, 11L, 14L, 14L, 16L, 16L, 14L, 20L, 20L, 18L, 10L,
19L, 12L, 19L, 14L, 19L, 15L, 19L, 14L, 20L, 17L, 20L, 19L, 15L,
18L, 20L, 19L, 16L, 20L, 20L, 14L, 15L, 16L, 19L, 18L, 14L, 20L,
20L, 19L, 20L, 11L, 19L, 13L, 19L, 14L, 20L, 15L, 20L, 16L, 20L,
17L, 20L, 20L, 16L, 18L, 20L, 19L, 16L, 20L, 20L, 15L, 17L, 16L,
20L, 19L, 16L, 20L, 20L, 20L, 20L, 11L, 19L, 12L, 19L, 13L, 19L,
14L, 20L, 14L, 20L, 16L, 20L, 19L, 14L, 16L, 20L, 18L, 15L, 20L,
19L, 14L, 15L, 15L, 19L, 18L, 15L, 20L, 20L, 19L, 20L, 9L, 19L,
12L, 18L, 12L, 19L, 13L, 19L, 13L, 20L, 15L, 19L, 18L, 13L, 15L,
20L, 18L, 14L, 19L, 19L, 13L, 14L, 14L, 18L, 18L, 13L, 20L, 20L,
18L, 20L, 2L), .Label = c("[1.15,3.11)", "[3.11,3.47)", "[3.47,3.77)",
"[3.77,4.02)", "[4.02,4.21)", "[4.21,4.41)", "[4.41,4.57)", "[4.57,4.75)",
"[4.75,4.93)", "[4.93,5.09)", "[5.09,5.24)", "[5.24,5.41)", "[5.41,5.58)",
"[5.58,5.77)", "[5.77,5.98)", "[5.98,6.17)", "[6.17,6.38)", "[6.38,6.70)",
"[6.70,7.08)", "[7.08,9.28]"), class = "factor")), .Names = c("var",
"mod", "low", "high", "var_ori"), row.names = c(NA, 150L), class = "data.frame")
labels<-c(0.86, 2.13, 3.29, 3.62, 3.895, 4.115, 4.31, 4.49, 4.66, 4.84,
5.01, 5.165, 5.325, 5.495, 5.675, 5.875, 6.075, 6.275, 6.54,
6.89, 8.18, 9.41)
#Graph:
graph<-ggplot(df2, aes(var,mod, group=1))+
geom_smooth(aes(color="red"), se=F, linetype="dotted", size=1)+
geom_line(data=df2,aes(var,low, color="red4"), size=1)+
geom_line(data=df2,aes(var,high, color="red4"), size=1)+
geom_ribbon(data=df2, aes(var,ymin=low,ymax=high), fill="lightpink", alpha=0.4)+
geom_smooth(data=df1, aes(var,mod, group=1, color="green"), se=F, linetype="dotted", size=1)+
geom_line(data=df1,aes(var,high, color="green4"), size=1)+
geom_line(data=df1,aes(var,low, color="green4"), size=1)+
geom_ribbon(data=df1, aes(var,ymin=low,ymax=high), fill="chartreuse1", alpha=0.4)+
ylim(min(df2$low,df1$low),max(df2$high,df1$high))+
scale_colour_manual(name = 'Legend',
values =c('red'='red','green'='green', 'green4'='green4', 'red4'='red4'), labels = c('1','interval-1','2','interval-2'))+
scale_size_area() +
xlab("mod var") +
ylab(expression(f[Tmax.an]))+
labs(title='Mod Var 1 2')
graph<-graph + theme(axis.title.y=element_text(size=18)) + theme(axis.title.y=element_text(size=18)) + scale_x_discrete(breaks=c(1:22), labels=c(paste(labels)))
对此事的任何帮助将不胜感激!提前谢谢。
答案 0 :(得分:1)
这对我来说似乎很合适:
df1b <- df1
df2b <- df2
df1b$var <- as.integer(as.character(df1b$var))
df2b$var <- as.integer(as.character(df2b$var))
graph<-ggplot(df2b, aes(var,mod, group=1))+
geom_smooth(aes(color="red"), se=F, linetype="dotted", size=1)+
geom_line(data=df2b,aes(var,low, color="red4"), size=1)+
geom_line(data=df2b,aes(var,high, color="red4"), size=1)+
geom_ribbon(data=df2b, aes(var,ymin=low,ymax=high), fill="lightpink", alpha=0.4)+
geom_smooth(data=df1b, aes(var,mod, group=1, color="green"), se=F, linetype="dotted", size=1)+
geom_line(data=df1b,aes(var,high, color="green4"), size=1)+
geom_line(data=df1b,aes(var,low, color="green4"), size=1)+
geom_ribbon(data=df1b, aes(var,ymin=low,ymax=high), fill="chartreuse1", alpha=0.4)+
ylim(min(df2b$low,df1b$low),max(df2b$high,df1b$high))+
scale_colour_manual(name = 'Legend',
values =c('red'='red','green'='green', 'green4'='green4', 'red4'='red4'),
labels = c('1','interval-1','2','interval-2'))+
scale_size_area() +
xlab("mod var") +
ylab(expression(f[Tmax.an]))+
labs(title='Mod Var 1 2')