下面是一个数据框(MeanRTE),用于每15分钟从2个位置收集的平均pH值。我已经使用带有误差线的ggplot绘制了所有数据。我只想绘制整个小时(即00:00、1:00、2:00等)的误差线,而不是全部15分钟的增量。我尝试在geom_errorbar中进行子集设置,但没有成功。
structure(list(Time = c("00:00", "00:15", "00:30", "00:45", "01:00",
"01:15", "01:30", "01:45", "02:00", "02:15", "02:30", "02:45",
"03:00", "03:15", "03:30", "03:45", "04:00", "04:15", "04:30",
"04:45", "05:00", "05:15", "05:30", "05:45", "06:00", "06:15",
"06:30", "06:45", "07:00", "07:15", "07:30", "07:45", "08:00",
"08:15", "08:30", "08:45", "09:00", "09:15", "09:30", "09:45",
"10:00", "10:15", "10:30", "10:45", "11:00", "11:15", "11:30",
"11:45", "12:00", "12:15", "12:30", "12:45", "13:00", "13:15",
"13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00",
"15:15", "15:30", "15:45", "16:00", "16:15", "16:30", "16:45",
"17:00", "17:15", "17:30", "17:45", "18:00", "18:15", "18:30",
"18:45", "19:00", "19:15", "19:30", "19:45", "20:00", "20:15",
"20:30", "20:45", "21:00", "21:15", "21:30", "21:45", "22:00",
"22:15", "22:30", "22:45", "23:00", "23:15", "23:30", "23:45"),
CpHInt = c(7.96171282, 7.96208845333333, 7.96103087333333,
7.96123868666667, 7.96087166666667, 7.9599384, 7.95962496666667,
7.95885009333333, 7.9584983, 7.95772246666667, 7.95729190666667,
7.9568308, 7.95623155333333, 7.95478404, 7.95451323333333,
7.95484769333333, 7.95416827333333, 7.95423304, 7.95348214666667,
7.95289884666667, 7.95253500666667, 7.95184953333333, 7.95176566,
7.95137232, 7.95039534666667, 7.94952766666667, 7.94912383333333,
7.94909797333333, 7.94958894666667, 7.95047576666667, 7.951112,
7.95214661333333, 7.95326046, 7.95520799333333, 7.95716933333333,
7.95943534, 7.96204385333333, 7.96429953333333, 7.96619530666667,
7.96806245333333, 7.97020228666667, 7.97219277333333,
7.97398587333333, 7.97599846, 8.03956957333333, 7.97926142,
7.98102154666667, 7.98301708, 7.98513370666667, 7.98624976666667,
7.9874123, 7.98876592, 7.98997548666667, 7.99096106666667,
7.99209892666667, 7.99324620666667, 7.99337482666667, 7.9945829,
7.99515315333333, 7.99629965333333, 7.99669175333333, 7.99706092,
7.9970385, 7.99756482, 7.99765972, 7.99744638666667,
7.99708054666667, 7.99640141333333, 7.99579072666667,
7.99484983333333, 7.9936607, 7.99268538, 7.99059010666667,
7.98885906, 7.98669008, 7.98475600666667, 7.98196531333333,
7.98030867333333, 7.97846984666667, 7.97649556, 7.97555104,
7.97474287333333, 7.97261089333333, 7.97231272666667,
7.97109830666667, 7.96974022666667, 7.96851739333333,
7.96808702, 7.96748405333333, 7.96654386, 7.96672288666667,
7.96576866666667, 7.96494012, 7.96478213333333, 7.96406474666667,
7.9628698), CSEMpHInt = c(0.0029708984810992,
0.00294034919996411, 0.00294534117975175, 0.00294033439308733,
0.00289075183330719, 0.00289513107139126, 0.00290311121636396,
0.00296456379138529, 0.00299174094916334, 0.00298176616653851,
0.00298867701725367, 0.00300394779211425, 0.00302801627329685,
0.00310710356972431, 0.00305024516977897, 0.00302187928062395,
0.00304639384680485, 0.00307316803752809, 0.00306186564087682,
0.00306504409044936, 0.00301906581509126, 0.00304709523812749,
0.00309587703093885, 0.00310825238667623, 0.00313827754566459,
0.00312415861034516, 0.00318400843021772, 0.00326083108701037,
0.00313501134488629, 0.00311984426447868, 0.00309290372632813,
0.00306713459549465, 0.00303906703458796, 0.00301757707885729,
0.00301249449215586, 0.00299270934409085, 0.0029818052519792,
0.00293670611009415, 0.00291721110026691, 0.00289174221602659,
0.00286271129921374, 0.00284218003758147, 0.00280278761883409,
0.00277944961242514, 0.0617819250871915, 0.00276248730636082,
0.00278369741037608, 0.00278405586556508, 0.00278213751592677,
0.00281637522825106, 0.00284494454513512, 0.00287386866018783,
0.00290021698759379, 0.00295303265640899, 0.00297257249766848,
0.00299334821648625, 0.00310563878150578, 0.00312506524446673,
0.00315631680228689, 0.00316704517782649, 0.00319531704652308,
0.00321350747324522, 0.00323741266416465, 0.00326924579358731,
0.00329109700536005, 0.00329225424315183, 0.00330930064995256,
0.00331979615977226, 0.00331437345638677, 0.00331489288526778,
0.00331398295772831, 0.00329941510322274, 0.0032983309488268,
0.00328318257745606, 0.00329811542627941, 0.00327926988565523,
0.00326447239785723, 0.0032451447607764, 0.0032193034364279,
0.00320555493779103, 0.00314649279319196, 0.00313739986533379,
0.0031411267290203, 0.0030956389858293, 0.00308748115604229,
0.00310237692973348, 0.00312521264056671, 0.0031058793535909,
0.00314247098830212, 0.00313896888133227, 0.00306581415383673,
0.00305469515056838, 0.00300928623672355, 0.00299131939557068,
0.00296884746703254, 0.00297801203030888), CCIpHInt =
c(0.00584651926473725, 0.00578640042802288, 0.00579622429315435,
0.00578637128913075, 0.00568879629867119, 0.00569741433122474,
0.00571311869527995, 0.00583405304090492, 0.00588753577601723,
0.00586790610534734, 0.00588150617350818, 0.00591155798442593,
0.00595892306263454, 0.00611456129972031, 0.00600266796753228,
0.00594684589267469, 0.00599508883478636, 0.00604777855907585,
0.00602553623737426, 0.00603179120258969, 0.00594130919038003,
0.00599646912357981, 0.0060924682609635, 0.00611682209068433,
0.00617590949187594, 0.00614812442016522, 0.00626590465638066,
0.00641708624193936, 0.00616948183845919, 0.00613963409093195,
0.0060866170066049, 0.00603590516949165, 0.00598067018364508,
0.00593837946217577, 0.00592837728901044, 0.00588944150912645,
0.0058679830227457, 0.0057792310833807, 0.00574086627514295,
0.00569074530220843, 0.00563361449969224, 0.00559321042078275,
0.00551568891119354, 0.0054697613559645, 0.121582483391077,
0.00543638073060477, 0.00547812072358036, 0.00547882613818181,
0.00547505096101295, 0.00554242837089686, 0.00559865077721795,
0.00565557140138164, 0.00570742305661408, 0.00581136057826705,
0.00584981361161045, 0.0058906987650681, 0.00611167869952618,
0.00614990861235203, 0.00621140948019084, 0.00623252216871612,
0.00628815921792405, 0.00632395669836352, 0.00637100043281854,
0.0064336457926686, 0.00647664744062121, 0.00647892480320583,
0.00651247093289995, 0.0065331253580661, 0.00652245385918726,
0.00652347605869317, 0.00652168538529155, 0.00649301687219541,
0.00649088333259378, 0.00646107240313528, 0.00649045919937842,
0.00645337250085452, 0.00642425208558919, 0.00638621665514488,
0.00633536274627153, 0.00630830666789892, 0.00619207652122376,
0.00617418227871301, 0.00618151648433424, 0.00609199980492984,
0.0060759457696568, 0.00610525960464738, 0.00615019867751029,
0.00611215212847002, 0.00618416189205785, 0.00617726999184764,
0.00603330663317676, 0.00601142521675454, 0.00592206366795925,
0.00588670618819513, 0.0058424830133038, 0.00586051822927934),
MpHInt = c(7.96392521088435, 7.96292867346939, 7.96167553741497,
7.96162205442177, 7.96191294557823, 7.96202844217687,
7.96164924489796, 7.96300917006803, 7.96358463265306,
7.96375802040816, 7.96399123809524, 7.96336131292517,
7.96214980272109, 7.96270961904762, 7.96384517687075,
7.9647585170068, 7.96342123809524, 7.9627337755102,
7.96158779591837, 7.96080521768708, 7.95902181632653,
7.95730180272109, 7.95561841496599, 7.95533358503401,
7.95372270068027, 7.95210751020408, 7.95057300680272,
7.94933710204082, 7.9484996122449, 7.94910646938775,
7.95164165986395, 7.95514455782313, 7.9602895170068,
7.96537525170068, 7.97148438095238, 7.97850011564626,
7.9852047414966, 7.99286048979592, 8.00043313605442,
8.00781662116041, 8.01507714285714, 8.02154542176871,
8.02737000680272, 8.03294027210884, 8.0376713877551,
8.04305546938775, 8.04723029351536, 8.05086187030717,
8.05375440273037, 8.05607115358362, 8.05897845733788,
8.06138139249147, 8.06319096928328, 8.06535455290102,
8.06670766552901, 8.06764116723549, 8.06843368707483,
8.06888653741497, 8.06978441496599, 8.07074242857143,
8.07142619727891, 8.07134906122449, 8.07136750340136,
8.07061963265306, 8.06973649659864, 8.06821497278912,
8.06632202040816, 8.06344455782313, 8.06068391836735,
8.0567341292517, 8.05211005442177, 8.04657148979592,
8.04130656462585, 8.03522941496599, 8.02832047619048,
8.02181020408163, 8.01522237414966, 8.00889197278912,
8.00266446258503, 7.99723936054422, 7.99133627210884,
7.98660408163265, 7.98258448979592, 7.97895927891156,
7.97596815646259, 7.97299004081633, 7.97046972789116,
7.96808000680272, 7.96528140816327, 7.96393509523809,
7.96362110204082, 7.96297610884354, 7.96261465306122,
7.96193226530612, 7.96261133333333, 7.96324569387755), MSEMpHInt =
c(0.00591429270544425, 0.00590832907532162, 0.00591431931395925,
0.00597573070478391, 0.00601025582774281, 0.00608457942288835,
0.00610313037881744, 0.00612085972747768, 0.00612875859156086,
0.0061339636844674, 0.00617745188202971, 0.00621757209798438,
0.00619854337563069, 0.00616056902575974, 0.00615768672051877,
0.0061525222423396, 0.0061491869772608, 0.00620682248584733,
0.00626274695383098, 0.00633232833810084, 0.00638416043837518,
0.00647792923303455, 0.00653584366521767, 0.00657400512493082,
0.0065733912094252, 0.00660474077531978, 0.0065586480435849,
0.00652424110971229, 0.0064271985935479, 0.00629343691250346,
0.00614897273360358, 0.0059593544187133, 0.00583868715276734,
0.00569919751759724, 0.00557905562631926, 0.00546551634592611,
0.00535497855559661, 0.00522404339157249, 0.00512291762073707,
0.00508266124274125, 0.00504314945024597, 0.005025317071252,
0.00502900302587727, 0.00501777610628446, 0.00496645058050499,
0.00493112939055476, 0.00486527142639433, 0.00480661179681194,
0.00479593763839434, 0.00478514483619342, 0.00475173891780512,
0.00471035230446746, 0.00471085361247356, 0.00471220114506174,
0.00467038316779996, 0.00465064307380344, 0.00473659682877564,
0.00477356830500068, 0.00468626773356603, 0.00468217390252226,
0.00464026229095549, 0.00463208575186507, 0.00463828842595173,
0.00462266385540932, 0.00463037024404264, 0.00463889772498533,
0.00469198742987112, 0.00469361511837987, 0.0047416510253956,
0.00475761185361311, 0.0048041113306535, 0.00480038548642405,
0.00483838274134001, 0.00485603387039978, 0.00489053913056093,
0.00492924703093015, 0.00499029353503576, 0.0050380342708441,
0.00505512783367472, 0.00510679255505491, 0.00516850937488745,
0.00524080042661711, 0.00527195818840782, 0.00535207868490291,
0.0053805718618602, 0.00545025029880762, 0.00550205194988136,
0.00554279465599259, 0.0056019815204785, 0.00571698193170248,
0.00580811628442547, 0.00582249920709368, 0.0059262648113405,
0.00592609319342444, 0.00595191299858725, 0.00592883864670328),
MCIpHInt = c(0.0116398807508405, 0.0116281437694419,
0.0116399331188847, 0.0117607964750869, 0.0118287451435354,
0.0119750209245213, 0.0120115309394263, 0.0120464239544449,
0.0120619696571306, 0.0120722137664006, 0.012157802603292,
0.0122367629376327, 0.0121993126337554, 0.0121245755644045,
0.0121189029183311, 0.0121087387426402, 0.0121021746292756,
0.0122156066963669, 0.0123256712756503, 0.0124626139424605,
0.0125646243596493, 0.0127491701104844, 0.0128631511252799,
0.0129382564442862, 0.0129370482011991, 0.0129987470765807,
0.012908032273037, 0.0128403162117554, 0.0126493274710603,
0.0123860719823767, 0.0121017529777365, 0.011728566413692,
0.0114910819576305, 0.011216553319935, 0.0109801028503178,
0.0107566469359536, 0.010539098234532, 0.01028140559549,
0.0100823806280112, 0.0100032943964172, 0.0099253894139351,
0.0098902936255913, 0.00989754792875619, 0.00987545230181176,
0.00977443887056963, 0.00970492346788759, 0.00957544484519889,
0.00945999557249053, 0.00943898753280705, 0.00941774598775379,
0.00935199908465295, 0.00927054520497948, 0.00927153183999779,
0.00927418394773124, 0.00919188109148448, 0.00915303018991355,
0.00932206520671629, 0.00939482852701085, 0.00922301284395476,
0.00921495580188112, 0.00913246983356513, 0.00911637764051567,
0.00912858508277474, 0.00909783446778924, 0.00911300136080231,
0.00912978424021351, 0.00923426974080415, 0.00923747318390122,
0.0093320123379926, 0.00936342473950691, 0.00945494005582332,
0.00944760724618961, 0.00952238939480968, 0.00955712846634468,
0.009625038042951, 0.0097012188082348, 0.00982136403327429,
0.00991532226284498, 0.00994896399193497, 0.0100506449918181,
0.0101721094608509, 0.0103143850064477, 0.0103757063934283,
0.0105333910180061, 0.0105894682530219, 0.0107266019285713,
0.0108285524188878, 0.0109087378720299, 0.0110252231525095,
0.0112515547088954, 0.0114309156318041, 0.0114592225677378,
0.0116634429740698, 0.0116631052139728, 0.0117139210034633,
0.0116685085225955)), .Names = c("Time", "CpHInt", "CSEMpHInt",
"CCIpHInt", "MpHInt", "MSEMpHInt", "MCIpHInt"), row.names = c(41L,
42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L,
55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L,
68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L,
81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L,
94L, 95L, 96L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L,
39L, 40L), class = "data.frame")
我想生成一个置信区间,其阴影线位于阴影下方,并且整小时显示每小时误差线的图。下面是生成记录了所有误差线的图的代码。
pHInt = ggplot(MeanRTE, aes(x=Time)) + geom_line(aes(y=CpHInt, color
= "Coco", group = 1), size = 0.5) + geom_errorbar(aes(ymin=CpHInt-
CSEMpHInt, ymax=CpHInt+CSEMpHInt, color = "Coco"), width=0.3) +
geom_line(aes(y=MpHInt, color = "Monty", group = 1), size = 0.5) +
geom_errorbar(aes(ymin=MpHInt-MSEMpHInt, ymax=MpHInt+MSEMpHInt,
color = "Monty"), width=0.3) + xlab("Time of Day") + ylab("Mean pH")
+ scale_x_discrete(breaks = c("00:00", "05:00", "10:00", "15:00",
"20:00")) + geom_ribbon(aes(ymin=CpHInt-CCIpHInt,
ymax=CpHInt+CCIpHInt, group = 1), fill = "brown3", alpha = 0.2,
linetype = 3) + geom_ribbon(aes(ymin=MpHInt-MCIpHInt,
ymax=MpHInt+MCIpHInt, group = 1), fill = "blue3", alpha = 0.2,
linetype = 3)
pHInt = pHInt + theme(aspect.ratio = .6, panel.grid.major =
element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), panel.border = element_rect(fill
= NA), legend.title = element_blank(), legend.key = element_blank(),
legend.position = c(0.9, 0.9), legend.key.size = unit(.5, "cm"),
legend.background = element_rect(fill = "white", linetype = "solid",
colour = "black", size = 0.25)) + scale_color_manual(values =
c("brown3", "blue3"))
pHInt