设置日期时间轴限制偏移值

时间:2016-02-05 13:03:46

标签: r datetime ggplot2 time-series

我有一个由几个部分组成的情节(见下文)。为了简单起见,我举了一个例子。它从一天的08:00开始,到同一天的09:00结束。时区是UTC。

df <- data.frame(x = as.POSIXct("2016-02-05 08:00:00", tz = "UTC"),
                 xend = as.POSIXct("2016-02-05 09:00:00", tz = "UTC"),
                 y = 1)

基本情节按预期工作,分段为08至09:

library(ggplot2)
ggplot(data = df, aes(x = x, xend = xend, y = y, yend =  y)) +
  geom_segment(size = 3)

enter image description here

然而,当我添加xlim时,x值会偏移一个小时(+1),并且该段的运行时间为09到10,而不是08到09.但是这些限制会正确显示(07 -10)。

ggplot(data = df, aes(x = x, xend = xend, y = y, yend =  y)) +
  geom_segment(size = 3) +
  xlim(as.POSIXct("2016-02-05 07:00:00"), as.POSIXct("2016-02-05 10:00:00"))

enter image description here

我想我对时区或如何设置轴限制有误解,但在查看了许多SO帖子和帮助页面后,我无法找到要点。我也尝试了scale_x_datetime(),但无法找到正确的设置。

如果有人有兴趣,请按照我的实际数据和相应的代码进行操作。正如您在数据的第一行中看到的那样,我的日期 - 时间列&#34; fecha&#34;从2016-02-05 08:07:00

开始
datos.uvi1[1,]
# fecha.hora latitud longitud altitud cobertura_nubosa longitud_de_onda  RGlobal   RDirecta
# 201602050807   37.75    -1.25     300             0.62           284.55 10.29363 0.00736326
   # RDifusa AnguloZenital blank               fecha
# 1 10.28627        79.872    NA 2016-02-05 08:07:00

但是,在图中,第一个x值出现在09:00。

ggplot(data = DF1, aes(x = x1, y = y1, xend = x2, yend = y2, colour = col)) +
  geom_segment(size = 1) + theme_bw() +
  xlim(as.POSIXct("2016-02-05 06:00:00"), as.POSIXct("2016-02-05 18:00:00")) +
  ylim(-100,500)

查找此处使用的数据

 dput(DF1)
structure(list(x1 = structure(c(1454630400, 1454631300, 1454632200, 
1454633100, 1454634000, 1454634900, 1454635800, 1454636700, 1454637600, 
1454638500, 1454639400, 1454640300, 1454641200, 1454642100, 1454643000, 
1454643900, 1454644800, 1454645700, 1454646600, 1454647500, 1454648400, 
1454649300, 1454650200, 1454651100, 1454652000, 1454652900, 1454653800, 
1454654700, 1454655600, 1454656500, 1454657400, 1454658300, 1454659200, 
1454660100, 1454661000, 1454661900, 1454662800, 1454663700, 1454664600, 
1454665500, 1454666400, 1454667300, 1454668200, 1454669100, 1454670000, 
1454670900, 1454671800, 1454672700, 1454673600, 1454674500, 1454675400, 
1454676300, 1454677200, 1454678100, 1454679000, 1454679900, 1454680800, 
1454681700, 1454682600, 1454683500, 1454684400, 1454685300, 1454686200, 
1454687100, 1454688000, 1454688900, 1454689800, 1454690700, 1454691600, 
1454692500, 1454693400, 1454694300, 1454695200, 1454696100, 1454697000, 
1454697900, 1454698800, 1454699700, 1454700600, 1454701500, 1454702400, 
1454703300, 1454704200, 1454705100, 1454706000, 1454706900, 1454707800, 
1454708700, 1454709600, 1454710500, 1454711400, 1454712300, 1454713200, 
1454714100, 1454715000, 1454715900, 1454716800, 1454717700, 1454718600, 
1454719500, 1454720400, 1454721300, 1454722200, 1454723100, 1454724000, 
1454724900, 1454725800, 1454726700, 1454727600, 1454728500, 1454729400, 
1454730300, 1454731200, 1454732100, 1454733000, 1454733900, 1454734800, 
1454735700, 1454736600, 1454737500, 1454738400, 1454739300, 1454740200, 
1454741100, 1454742000, 1454742900, 1454743800, 1454744700, 1454745600, 
1454746500, 1454747400, 1454748300, 1454749200, 1454750100, 1454751000, 
1454751900, 1454752800, 1454753700, 1454754600, 1454755500, 1454756400, 
1454757300, 1454758200, 1454759100, 1454760000, 1454760900, 1454761800, 
1454762700, 1454763600, 1454764500, 1454765400, 1454766300, 1454767200, 
1454768100, 1454769000, 1454769900, 1454770800, 1454771700, 1454772600, 
1454773500, 1454774400, 1454775300, 1454776200, 1454777100, 1454778000, 
1454778900, 1454779800, 1454780700, 1454781600, 1454782500, 1454783400, 
1454784300, 1454785200, 1454786100, 1454787000, 1454787900, 1454788800, 
1454789700, 1454790600, 1454791500, 1454792400, 1454793300, 1454794200, 
1454795100, 1454796000, 1454796900, 1454797800, 1454798700, 1454799600, 
1454800500, 1454801400, 1454802300, 1454803200, 1454804100, 1454805000, 
1454805900, 1454806800, 1454807700, 1454808600, 1454809500, 1454810400, 
1454811300, 1454812200, 1454813100, 1454814000, 1454814900, 1454815800, 
1454816700, 1454817600, 1454818500, 1454819400, 1454820300, 1454821200, 
1454822100, 1454823000, 1454823900, 1454824800, 1454825700, 1454826600, 
1454827500, 1454828400, 1454829300, 1454830200, 1454831100, 1454832000, 
1454832900, 1454833800, 1454834700, 1454835600, 1454836500, 1454837400, 
1454838300, 1454839200, 1454840100, 1454841000, 1454841900, 1454842800, 
1454843700, 1454844600, 1454845500, 1454846400, 1454847300, 1454848200, 
1454849100, 1454850000, 1454850900, 1454851800, 1454852700, 1454853600, 
1454854500, 1454855400, 1454856300, 1454857200, 1454858100, 1454859000, 
1454859900, 1454860800, 1454861700, 1454862600, 1454863500, 1454864400, 
1454865300, 1454866200, 1454867100, 1454868000, 1454868900, 1454869800, 
1454870700, 1454871600, 1454872500, 1454873400, 1454874300, 1454875200, 
1454876100, 1454877000, 1454877900, 1454878800, 1454879700, 1454880600, 
1454881500, 1454882400, 1454883300, 1454884200, 1454885100, 1454886000, 
1454886900, 1454887800, 1454888700), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), x2 = structure(c(1454631300, 1454632200, 1454633100, 
1454634000, 1454634900, 1454635800, 1454636700, 1454637600, 1454638500, 
1454639400, 1454640300, 1454641200, 1454642100, 1454643000, 1454643900, 
1454644800, 1454645700, 1454646600, 1454647500, 1454648400, 1454649300, 
1454650200, 1454651100, 1454652000, 1454652900, 1454653800, 1454654700, 
1454655600, 1454656500, 1454657400, 1454658300, 1454659200, 1454660100, 
1454661000, 1454661900, 1454662800, 1454663700, 1454664600, 1454665500, 
1454666400, 1454667300, 1454668200, 1454669100, 1454670000, 1454670900, 
1454671800, 1454672700, 1454673600, 1454674500, 1454675400, 1454676300, 
1454677200, 1454678100, 1454679000, 1454679900, 1454680800, 1454681700, 
1454682600, 1454683500, 1454684400, 1454685300, 1454686200, 1454687100, 
1454688000, 1454688900, 1454689800, 1454690700, 1454691600, 1454692500, 
1454693400, 1454694300, 1454695200, 1454696100, 1454697000, 1454697900, 
1454698800, 1454699700, 1454700600, 1454701500, 1454702400, 1454703300, 
1454704200, 1454705100, 1454706000, 1454706900, 1454707800, 1454708700, 
1454709600, 1454710500, 1454711400, 1454712300, 1454713200, 1454714100, 
1454715000, 1454715900, 1454716800, 1454717700, 1454718600, 1454719500, 
1454720400, 1454721300, 1454722200, 1454723100, 1454724000, 1454724900, 
1454725800, 1454726700, 1454727600, 1454728500, 1454729400, 1454730300, 
1454731200, 1454732100, 1454733000, 1454733900, 1454734800, 1454735700, 
1454736600, 1454737500, 1454738400, 1454739300, 1454740200, 1454741100, 
1454742000, 1454742900, 1454743800, 1454744700, 1454745600, 1454746500, 
1454747400, 1454748300, 1454749200, 1454750100, 1454751000, 1454751900, 
1454752800, 1454753700, 1454754600, 1454755500, 1454756400, 1454757300, 
1454758200, 1454759100, 1454760000, 1454760900, 1454761800, 1454762700, 
1454763600, 1454764500, 1454765400, 1454766300, 1454767200, 1454768100, 
1454769000, 1454769900, 1454770800, 1454771700, 1454772600, 1454773500, 
1454774400, 1454775300, 1454776200, 1454777100, 1454778000, 1454778900, 
1454779800, 1454780700, 1454781600, 1454782500, 1454783400, 1454784300, 
1454785200, 1454786100, 1454787000, 1454787900, 1454788800, 1454789700, 
1454790600, 1454791500, 1454792400, 1454793300, 1454794200, 1454795100, 
1454796000, 1454796900, 1454797800, 1454798700, 1454799600, 1454800500, 
1454801400, 1454802300, 1454803200, 1454804100, 1454805000, 1454805900, 
1454806800, 1454807700, 1454808600, 1454809500, 1454810400, 1454811300, 
1454812200, 1454813100, 1454814000, 1454814900, 1454815800, 1454816700, 
1454817600, 1454818500, 1454819400, 1454820300, 1454821200, 1454822100, 
1454823000, 1454823900, 1454824800, 1454825700, 1454826600, 1454827500, 
1454828400, 1454829300, 1454830200, 1454831100, 1454832000, 1454832900, 
1454833800, 1454834700, 1454835600, 1454836500, 1454837400, 1454838300, 
1454839200, 1454840100, 1454841000, 1454841900, 1454842800, 1454843700, 
1454844600, 1454845500, 1454846400, 1454847300, 1454848200, 1454849100, 
1454850000, 1454850900, 1454851800, 1454852700, 1454853600, 1454854500, 
1454855400, 1454856300, 1454857200, 1454858100, 1454859000, 1454859900, 
1454860800, 1454861700, 1454862600, 1454863500, 1454864400, 1454865300, 
1454866200, 1454867100, 1454868000, 1454868900, 1454869800, 1454870700, 
1454871600, 1454872500, 1454873400, 1454874300, 1454875200, 1454876100, 
1454877000, 1454877900, 1454878800, 1454879700, 1454880600, 1454881500, 
1454882400, 1454883300, 1454884200, 1454885100, 1454886000, 1454886900, 
1454887800, 1454888700, 1454889600), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), y1 = c(-2.32818864014106e-16, -0.452024674473069, 
-0.865524518735365, -1.24049953278689, -1.57694971662764, -1.87487507025761, 
-2.13427559367682, -2.35515128688525, -2.53750214988291, -2.68132818266979, 
-2.78662938524591, -2.85340575761125, -2.88165729976581, -2.87138401170961, 
-2.82258589344263, -2.73526294496488, -2.60941516627635, -2.44504255737705, 
-2.24214511826698, -2.00072284894614, -1.72077574941452, -1.40230381967213, 
-1.04530705971897, -0.649785469555037, -0.215739049180329, 0.11010970958345, 
-0.094992190282418, -0.0830157467530507, 1.03880660609386, 4.35105578267959, 
11.2292275706581, 21.4648924478395, 34.6589357571434, 50.4122428414893, 
68.3256990437967, 88.0001897069853, 109.036600173974, 131.035815787684, 
153.598721891033, 176.326203826942, 198.819146938329, 220.678436568115, 
241.504958059219, 260.899596754561, 278.463237997059, 293.796767129634, 
306.501069495206, 316.177030436693, 322.425535297016, 324.847469419093, 
323.187624835595, 317.720491485582, 308.830217189064, 296.900795628493, 
282.316220486325, 265.460485445013, 246.717584187012, 226.471510394776, 
205.106257750759, 183.005819937416, 160.554190637199, 138.135363532565, 
116.133332305967, 94.9320906398583, 74.9156322166944, 56.4679507189292, 
39.9730398290167, 25.8148932294113, 14.3775046025672, 6.0448676309385, 
1.16900796647366, -1.14737991651661, -1.87433146240601, -1.57099549478653, 
-0.796520837250196, -0.110056313389011, -0.0476392620865144, 
-0.27154379389313, -0.471628694656489, -0.647893964376591, -0.800339603053436, 
-0.928965610687024, -1.03377198727735, -1.11475873282443, -1.17192584732824, 
-1.2052733307888, -1.21480118320611, -1.20050940458015, -1.16239799491094, 
-1.10046695419847, -1.01471628244275, -0.905145979643766, -0.771756045801527, 
-0.614546480916031, -0.433517284987277, -0.228668458015267, 1.43049465231148e-16, 
0.0476059566987251, -0.263571083854407, -0.892788667022668, -1.79930433816933, 
-2.94237564265767, -4.28126012585096, -5.77521533311247, -7.38349880980547, 
-9.06536810129324, -10.780080752939, -12.4868943101062, -14.1450663181579, 
-15.7138543224574, -17.1525158683681, -18.4203085012532, -19.476489766476, 
-20.2803172093997, -20.7910483753877, -20.9679408098031, -20.7702520580093, 
-20.1572396653696, -19.0881611772472, -17.5222741390053, -15.4188360960073, 
-12.7371045936165, -9.43633717719601, -5.47579139210924, -0.814724783719416, 
4.73582755402823, 11.7311922232192, 20.0617832665983, 29.5462146556178, 
40.0031003617296, 51.2510543563856, 63.1086906110381, 75.3946230971389, 
87.9274657861401, 100.525832649494, 113.008337658652, 125.193594785066, 
136.900218000189, 147.946821275473, 158.152018582369, 167.33442389233, 
175.312651176807, 181.905314407253, 186.93102755512, 190.208404591859, 
191.556059488923, 190.827712855524, 188.111189681653, 183.589336614547, 
177.445249320869, 169.862023467283, 161.022754720454, 151.110538747044, 
140.308471213718, 128.799647787139, 116.767164133971, 104.394115920878, 
91.8635988145229, 79.3587084815701, 67.0625405886831, 55.1581908025256, 
43.8287547897614, 33.2573282170542, 23.6270067510677, 15.1208860584656, 
7.9220618059117, 2.20565169571042, -2.44620646798441, -6.3856154382178, 
-9.65596111011076, -12.3006293787843, -14.3630061393594, -15.8864772869571, 
-16.9144287166984, -17.4902463237042, -17.6573160030957, -17.4590236499938, 
-16.9387551595194, -16.1398964267937, -15.1058333469376, -13.8799518150721, 
-12.5056377263182, -11.026276975797, -9.48525545862936, -7.92595906993638, 
-6.39177370483904, -4.92608525845835, -3.57227962591531, -2.37374270233092, 
-1.37386038282619, -0.616018562522125, -0.143603136539726, 4.05491612509579e-17, 
-0.269113291953477, -0.971281430690497, -2.05454173019178, -3.46693150443803, 
-5.15648806740998, -7.07124873308833, -9.15925081545381, -11.3685316284871, 
-13.647128486169, -15.9430787024802, -18.2044195914013, -20.3791884669132, 
-22.4154226429964, -24.2611594336319, -25.8644361528001, -27.173290114482, 
-28.1357586326581, -28.6998790213092, -28.8136885944161, -28.4252246659594, 
-27.4825245499199, -25.9336255602782, -23.7265650110151, -20.8093802161114, 
-17.1301084895476, -12.6367871453046, -7.27745349736302, -1.00014485970363, 
6.49491281706241, 15.9294328047396, 27.1297815784381, 39.8549473186191, 
53.8639182057439, 68.9156824202737, 84.7692281426695, 101.183543553393, 
117.917616832904, 134.730436161666, 151.380989720138, 167.628265688782, 
183.23125224806, 197.948937578432, 211.54030986036, 223.764357274305, 
234.380068000728, 243.14643022009, 249.822432112853, 254.167061859477, 
255.939307640424, 254.943444889699, 251.294252044968, 245.235185222388, 
237.010065191466, 226.862712721707, 215.036948582618, 201.776593543703, 
187.32546837447, 171.927393844423, 155.826190723069, 139.265679779912, 
122.48968178446, 105.742017506218, 89.266507714692, 73.306973179387, 
58.1072346698093, 43.9111129554647, 30.9624288058589, 19.5050029904979, 
9.78265627888729, 2.03544075407098, -4.49253613154634, -10.5045377609422, 
-16.0005641341166, -20.9806152510694, -25.4446911118009, -29.3927917163108, 
-32.8249170645993, -35.7410671566663, -38.1412419925118, -40.0254415721358, 
-41.3936658955384, -42.2459149627195, -42.5821887736791, -42.4024873284173, 
-41.706810626934, -40.4951586692291, -38.7675314553029, -36.5239289851551, 
-33.7643512587859, -30.4887982761952, -26.697270037383, -22.3897665423494, 
-17.5662877910942, -12.2268337836176, -6.37140451991957), y2 = c(-0.452024674473069, 
-0.865524518735365, -1.24049953278689, -1.57694971662764, -1.87487507025761, 
-2.13427559367682, -2.35515128688525, -2.53750214988291, -2.68132818266979, 
-2.78662938524591, -2.85340575761125, -2.88165729976581, -2.87138401170961, 
-2.82258589344263, -2.73526294496488, -2.60941516627635, -2.44504255737705, 
-2.24214511826698, -2.00072284894614, -1.72077574941452, -1.40230381967213, 
-1.04530705971897, -0.649785469555037, -0.215739049180329, 0.11010970958345, 
-0.094992190282418, -0.0830157467530507, 1.03880660609386, 4.35105578267959, 
11.2292275706581, 21.4648924478395, 34.6589357571434, 50.4122428414893, 
68.3256990437967, 88.0001897069853, 109.036600173974, 131.035815787684, 
153.598721891033, 176.326203826942, 198.819146938329, 220.678436568115, 
241.504958059219, 260.899596754561, 278.463237997059, 293.796767129634, 
306.501069495206, 316.177030436693, 322.425535297016, 324.847469419093, 
323.187624835595, 317.720491485582, 308.830217189064, 296.900795628493, 
282.316220486325, 265.460485445013, 246.717584187012, 226.471510394776, 
205.106257750759, 183.005819937416, 160.554190637199, 138.135363532565, 
116.133332305967, 94.9320906398583, 74.9156322166944, 56.4679507189292, 
39.9730398290167, 25.8148932294113, 14.3775046025672, 6.0448676309385, 
1.16900796647366, -1.14737991651661, -1.87433146240601, -1.57099549478653, 
-0.796520837250196, -0.110056313389011, -0.0476392620865144, 
-0.27154379389313, -0.471628694656489, -0.647893964376591, -0.800339603053436, 
-0.928965610687024, -1.03377198727735, -1.11475873282443, -1.17192584732824, 
-1.2052733307888, -1.21480118320611, -1.20050940458015, -1.16239799491094, 
-1.10046695419847, -1.01471628244275, -0.905145979643766, -0.771756045801527, 
-0.614546480916031, -0.433517284987277, -0.228668458015267, 1.43049465231148e-16, 
0.0476059566987251, -0.263571083854407, -0.892788667022668, -1.79930433816933, 
-2.94237564265767, -4.28126012585096, -5.77521533311247, -7.38349880980547, 
-9.06536810129324, -10.780080752939, -12.4868943101062, -14.1450663181579, 
-15.7138543224574, -17.1525158683681, -18.4203085012532, -19.476489766476, 
-20.2803172093997, -20.7910483753877, -20.9679408098031, -20.7702520580093, 
-20.1572396653696, -19.0881611772472, -17.5222741390053, -15.4188360960073, 
-12.7371045936165, -9.43633717719601, -5.47579139210924, -0.814724783719416, 
4.73582755402823, 11.7311922232192, 20.0617832665983, 29.5462146556178, 
40.0031003617296, 51.2510543563856, 63.1086906110381, 75.3946230971389, 
87.9274657861401, 100.525832649494, 113.008337658652, 125.193594785066, 
136.900218000189, 147.946821275473, 158.152018582369, 167.33442389233, 
175.312651176807, 181.905314407253, 186.93102755512, 190.208404591859, 
191.556059488923, 190.827712855524, 188.111189681653, 183.589336614547, 
177.445249320869, 169.862023467283, 161.022754720454, 151.110538747044, 
140.308471213718, 128.799647787139, 116.767164133971, 104.394115920878, 
91.8635988145229, 79.3587084815701, 67.0625405886831, 55.1581908025256, 
43.8287547897614, 33.2573282170542, 23.6270067510677, 15.1208860584656, 
7.9220618059117, 2.20565169571042, -2.44620646798441, -6.3856154382178, 
-9.65596111011076, -12.3006293787843, -14.3630061393594, -15.8864772869571, 
-16.9144287166984, -17.4902463237042, -17.6573160030957, -17.4590236499938, 
-16.9387551595194, -16.1398964267937, -15.1058333469376, -13.8799518150721, 
-12.5056377263182, -11.026276975797, -9.48525545862936, -7.92595906993638, 
-6.39177370483904, -4.92608525845835, -3.57227962591531, -2.37374270233092, 
-1.37386038282619, -0.616018562522125, -0.143603136539726, 4.05491612509579e-17, 
-0.269113291953477, -0.971281430690497, -2.05454173019178, -3.46693150443803, 
-5.15648806740998, -7.07124873308833, -9.15925081545381, -11.3685316284871, 
-13.647128486169, -15.9430787024802, -18.2044195914013, -20.3791884669132, 
-22.4154226429964, -24.2611594336319, -25.8644361528001, -27.173290114482, 
-28.1357586326581, -28.6998790213092, -28.8136885944161, -28.4252246659594, 
-27.4825245499199, -25.9336255602782, -23.7265650110151, -20.8093802161114, 
-17.1301084895476, -12.6367871453046, -7.27745349736302, -1.00014485970363, 
6.49491281706241, 15.9294328047396, 27.1297815784381, 39.8549473186191, 
53.8639182057439, 68.9156824202737, 84.7692281426695, 101.183543553393, 
117.917616832904, 134.730436161666, 151.380989720138, 167.628265688782, 
183.23125224806, 197.948937578432, 211.54030986036, 223.764357274305, 
234.380068000728, 243.14643022009, 249.822432112853, 254.167061859477, 
255.939307640424, 254.943444889699, 251.294252044968, 245.235185222388, 
237.010065191466, 226.862712721707, 215.036948582618, 201.776593543703, 
187.32546837447, 171.927393844423, 155.826190723069, 139.265679779912, 
122.48968178446, 105.742017506218, 89.266507714692, 73.306973179387, 
58.1072346698093, 43.9111129554647, 30.9624288058589, 19.5050029904979, 
9.78265627888729, 2.03544075407098, -4.49253613154634, -10.5045377609422, 
-16.0005641341166, -20.9806152510694, -25.4446911118009, -29.3927917163108, 
-32.8249170645993, -35.7410671566663, -38.1412419925118, -40.0254415721358, 
-41.3936658955384, -42.2459149627195, -42.5821887736791, -42.4024873284173, 
-41.706810626934, -40.4951586692291, -38.7675314553029, -36.5239289851551, 
-33.7643512587859, -30.4887982761952, -26.697270037383, -22.3897665423494, 
-17.5662877910942, -12.2268337836176, -6.37140451991957, -2.04350425470068e-14
), col = structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1L, 
NA, NA, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, 1L, 1L, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA), .Label = c("(0,250]", "(250,500]", "(500,1e+03]"
), class = "factor")), .Names = c("x1", "x2", "y1", "y2", "col"
), row.names = c("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"), class = "data.frame")

1 个答案:

答案 0 :(得分:2)

问题在于您当地时间与您使用的UTC时间之间的差异,以及ggplot显示设置限制时的那些时间。

要解决此问题,您必须使用scale_x_datetime()并提供时区UTC限制,并在时区UTC添加参数time_trans()

library(scales)    
ggplot(data=DF1, aes(x=x1, y=y1, xend = x2, yend = y2, colour=col)) +
      geom_segment(size = 1) + theme_bw() +
      scale_x_datetime(limits=c(as.POSIXct("2016-02-05 06:00:00",tz="UTC"), as.POSIXct("2016-02-05 18:00:00",tz="UTC")),
                       date_breaks="1 hour",labels=date_format("%H:%M"),
                       time_trans(tz="UTC"))+
      ylim(-100,500)

enter image description here