2016-11-19 103 views
1

我正在嘗試繪製一些時間序列數據,並在一天之內對其進行打分。我在管理方面沒有問題,但無法理解爲什麼每天的x軸不按正確的順序排列。也就是說,不是從0:00開始到23:59結束,而是從22:00開始到22:00結束。任何幫助,不勝感激:R/ggplot2 - 按天排序,按錯誤順序排列

enter image description here

#Convert Datetime column to R POSIXct 
original_data$Date<-as.POSIXct(x = original_data$Date, format = "%m/%d/%Y %H:%M") 

#Set reference values to numeric 
original_data$Reference<-as.numeric(original_data$Reference) 

calibration_plot<-ggplot(original_data, aes(Date, Reference)) + 
facet_wrap(~DOY, scales = "free") + xlab("Time (hours)") + 
geom_point()+  ylab(expression(Radiation ~ (W ~ m^{-2}))) + 
scale_x_datetime(labels = date_format("%H")) + ggtitle("Calibration 
Plots") + theme_bw() + theme(axis.text=element_text(size=12), 
axis.title=element_text(size=12,face="bold"), title = 
element_text(size=10, face = "bold")) 


Date DOY Reference 
11/7/2016 0:01 312 -0.0137 
11/7/2016 0:06 312 -0.01525 
11/7/2016 0:11 312 -0.01325 
11/7/2016 0:16 312 -0.
11/7/2016 0:21 312 -0.0119 
11/7/2016 0:26 312 -0.0112 
11/7/2016 0:31 312 -0.0109 
11/7/2016 0:36 312 -0.0112 
11/7/2016 0:41 312 -0.0105 
11/7/2016 0:46 312 -0.00865 
11/7/2016 0:51 312 -0.00875 
11/7/2016 0:56 312 -0.0081 
11/7/2016 1:01 312 -0.00885 
11/7/2016 1:06 312 -0.00775 
11/7/2016 1:11 312 -0.0086 
11/7/2016 1:16 312 -0.0085 
11/7/2016 1:21 312 -0.00915 
11/7/2016 1:26 312 -0.0077 
11/7/2016 1:31 312 -0.0114 
11/7/2016 1:36 312 -0.0148 
11/7/2016 1:41 312 -0.0121 
11/7/2016 1:46 312 -0.012 
11/7/2016 1:51 312 -0.0121 
11/7/2016 1:56 312 -0.0086 
11/7/2016 2:01 312 -0.00915 
11/7/2016 2:06 312 -0.00945 
11/7/2016 2:11 312 -0.0072 
11/7/2016 2:16 312 -0.00485 
11/7/2016 2:21 312 -0.006 
11/7/2016 2:26 312 -0.00605 
11/7/2016 2:31 312 -0.00685 
11/7/2016 2:36 312 -0.00905 
11/7/2016 2:41 312 -0.01085 
11/7/2016 2:46 312 -0.0133 
11/7/2016 2:51 312 -0.0118 
11/7/2016 2:56 312 -0.01285 
11/7/2016 3:01 312 -0.0125 
11/7/2016 3:06 312 -0.0108 
11/7/2016 3:11 312 -0.0114 
11/7/2016 3:16 312 -0.01165 
11/7/2016 3:21 312 -0.0117 
11/7/2016 3:26 312 -0.0116 
11/7/2016 3:31 312 -0.01155 
11/7/2016 3:36 312 -0.01345 
11/7/2016 3:41 312 -0.01375 
11/7/2016 3:46 312 -0.01405 
11/7/2016 3:51 312 -0.01195 
11/7/2016 3:56 312 -0.012 
11/7/2016 4:01 312 -0.0115 
11/7/2016 4:06 312 -0.01215 
11/7/2016 4:11 312 -0.01155 
11/7/2016 4:16 312 -0.013 
11/7/2016 4:21 312 -0.01135 
11/7/2016 4:26 312 -0.01165 
11/7/2016 4:31 312 -0.01125 
11/7/2016 4:36 312 -0.01025 
11/7/2016 4:41 312 -0.0106 
11/7/2016 4:46 312 -0.0118 
11/7/2016 4:51 312 -0.01045 
11/7/2016 4:56 312 -0.0108 
11/7/2016 5:01 312 -0.01315 
11/7/2016 5:06 312 -0.01155 
11/7/2016 5:11 312 -0.01195 
11/7/2016 5:16 312 -0.01255 
11/7/2016 5:21 312 -0.01145 
11/7/2016 5:26 312 -0.011 
11/7/2016 5:31 312 -0.0108 
11/7/2016 5:36 312 -0.01115 
11/7/2016 5:41 312 -0.0104 
11/7/2016 5:46 312 -0.00325 
11/7/2016 5:51 312 0.01585 
11/7/2016 5:56 312 0.0383 
11/7/2016 6:01 312 0.0541 
11/7/2016 6:06 312 0.08845 
11/7/2016 6:11 312 0.16495 
11/7/2016 6:16 312 0.2525 
11/7/2016 6:21 312 0.3453 
11/7/2016 6:26 312 0.4411 
11/7/2016 6:31 312 0.5581 
11/7/2016 6:36 312 0.73945 
11/7/2016 6:41 312 0.84045 
11/7/2016 6:46 312 1.0619 
11/7/2016 6:51 312 1.50535 
11/7/2016 6:56 312 1.7774 
11/7/2016 7:01 312 1.9699 
11/7/2016 7:06 312 1.94915 
11/7/2016 7:11 312 1.984 
11/7/2016 7:16 312 2.17855 
11/7/2016 7:21 312 2.5005 
11/7/2016 7:26 312 2.35345 
11/7/2016 7:31 312 2.43305 
11/7/2016 7:36 312 2.63425 
11/7/2016 7:41 312 3.16065 
11/7/2016 7:46 312 3.34475 
11/7/2016 7:51 312 3.2605 
11/7/2016 7:56 312 3.3372 
11/7/2016 8:01 312 3.3398 
11/7/2016 8:06 312 3.43235 
11/7/2016 8:11 312 3.8922 
11/7/2016 8:16 312 4.359 
11/7/2016 8:21 312 4.4112 
11/7/2016 8:26 312 4.7168 
11/7/2016 8:31 312 4.8878 
11/7/2016 8:36 312 5.05045 
11/7/2016 8:41 312 5.20745 
11/7/2016 8:46 312 4.82285 
11/7/2016 8:51 312 5.19705 
11/7/2016 8:56 312 4.9623 
11/7/2016 9:01 312 5.164 
11/7/2016 9:06 312 5.85755 
11/7/2016 9:11 312 5.91635 
11/7/2016 9:16 312 6.20635 
11/7/2016 9:21 312 6.3367 
11/7/2016 9:26 312 6.4511 
11/7/2016 9:31 312 6.5009 
11/7/2016 9:36 312 6.55115 
11/7/2016 9:41 312 6.77255 
11/7/2016 9:46 312 6.73385 
11/7/2016 9:51 312 6.739 
11/7/2016 9:56 312 7.0979 
11/7/2016 10:01 312 7.2608 
11/7/2016 10:06 312 7.39525 
11/7/2016 10:11 312 7.32865 
11/7/2016 10:16 312 7.4016 
11/7/2016 10:21 312 7.70725 
11/7/2016 10:26 312 7.8645 
11/7/2016 10:31 312 7.8682 
11/7/2016 10:36 312 8.0161 
11/7/2016 10:41 312 7.7934 
11/7/2016 10:46 312 5.99495 
11/7/2016 10:51 312 8.25685 
11/7/2016 10:56 312 8.7265 
11/7/2016 11:01 312 8.5505 
11/7/2016 11:06 312 8.1372 
11/7/2016 11:11 312 5.0642 
11/7/2016 11:16 312 5.0355 
11/7/2016 11:21 312 6.32535 
11/7/2016 11:26 312 5.8676 
11/7/2016 11:31 312 7.37175 
11/7/2016 11:36 312 6.1949 
11/7/2016 11:41 312 5.01225 
11/7/2016 11:46 312 5.91725 
11/7/2016 11:51 312 6.7572 
11/7/2016 11:56 312 7.70375 
11/7/2016 12:01 312 8.12815 
11/7/2016 12:06 312 6.04805 
11/7/2016 12:11 312 5.2638 
11/7/2016 12:16 312 4.85 
11/7/2016 12:21 312 4.2291 
11/7/2016 12:26 312 4.2851 
11/7/2016 12:31 312 4.99735 
11/7/2016 12:36 312 4.7308 
11/7/2016 12:41 312 5.2383 
11/7/2016 12:46 312 6.9894 
11/7/2016 12:51 312 6.8357 
11/7/2016 12:56 312 9.124 
11/7/2016 13:01 312 9.2875 
11/7/2016 13:06 312 7.11615 
11/7/2016 13:11 312 7.8034 
11/7/2016 13:16 312 5.29235 
11/7/2016 13:21 312 6.02785 
11/7/2016 13:26 312 5.6154 
11/7/2016 13:31 312 3.5963 
11/7/2016 13:36 312 2.88325 
11/7/2016 13:41 312 2.7976 
11/7/2016 13:46 312 3.07845 
11/7/2016 13:51 312 3.55455 
11/7/2016 13:56 312 3.2716 
11/7/2016 14:01 312 2.8856 
11/7/2016 14:06 312 4.42685 
11/7/2016 14:11 312 6.93045 
11/7/2016 14:16 312 6.68565 
11/7/2016 14:21 312 6.0181 
11/7/2016 14:26 312 3.3964 
11/7/2016 14:31 312 3.3697 
11/7/2016 14:36 312 2.99275 
11/7/2016 14:41 312 5.2926 
11/7/2016 14:46 312 4.70665 
11/7/2016 14:51 312 4.16065 
11/7/2016 14:56 312 3.7451 
11/7/2016 15:01 312 3.47665 
11/7/2016 15:06 312 3.2893 
11/7/2016 15:11 312 3.0863 
11/7/2016 15:16 312 2.9122 
11/7/2016 15:21 312 2.71525 
11/7/2016 15:26 312 2.50645 
11/7/2016 15:31 312 2.26005 
11/7/2016 15:36 312 2.0562 
11/7/2016 15:41 312 1.89285 
11/7/2016 15:46 312 1.3635 
11/7/2016 15:51 312 1.1739 
11/7/2016 15:56 312 1.4291 
11/7/2016 16:01 312 1.1776 
11/7/2016 16:06 312 1.03155 
11/7/2016 16:11 312 0.8916 
11/7/2016 16:16 312 0.73225 
11/7/2016 16:21 312 0.6009 
11/7/2016 16:26 312 0.47795 
11/7/2016 16:31 312 0.35235 
11/7/2016 16:36 312 0.2142 
11/7/2016 16:41 312 0.11565 
11/7/2016 16:46 312 0.04355 
11/7/2016 16:51 312 0.0127 
11/7/2016 16:56 312 -0.00405 
11/7/2016 17:01 312 -0.0198 
11/7/2016 17:06 312 -0.02375 
11/7/2016 17:11 312 -0.0219 
11/7/2016 17:16 312 -0.01975 
11/7/2016 17:21 312 -0.02105 
11/7/2016 17:26 312 -0.02275 
11/7/2016 17:31 312 -0.022 
11/7/2016 17:36 312 -0.02135 
11/7/2016 17:41 312 -0.02165 
11/7/2016 17:46 312 -0.0232 
11/7/2016 17:51 312 -0.01995 
11/7/2016 17:56 312 -0.02085 
11/7/2016 18:01 312 -0.0197 
11/7/2016 18:06 312 -0.02185 
11/7/2016 18:11 312 -0.0213 
11/7/2016 18:16 312 -0.022 
11/7/2016 18:21 312 -0.01915 
11/7/2016 18:26 312 -0.0211 
11/7/2016 18:31 312 -0.02025 
11/7/2016 18:36 312 -0.0198 
11/7/2016 18:41 312 -0.0205 
11/7/2016 18:46 312 -0.0212 
11/7/2016 18:51 312 -0.0212 
11/7/2016 18:56 312 -0.0221 
11/7/2016 19:01 312 -0.0209 
11/7/2016 19:06 312 -0.0214 
11/7/2016 19:11 312 -0.02025 
11/7/2016 19:16 312 -0.02115 
11/7/2016 19:21 312 -0.02205 
11/7/2016 19:26 312 -0.0225 
11/7/2016 19:31 312 -0.0216 
11/7/2016 19:36 312 -0.0206 
11/7/2016 19:41 312 -0.02145 
11/7/2016 19:46 312 -0.0214 
11/7/2016 19:51 312 -0.02115 
11/7/2016 19:56 312 -0.021 
11/7/2016 20:01 312 -0.02075 
11/7/2016 20:06 312 -0.0224 
11/7/2016 20:11 312 -0.02035 
11/7/2016 20:16 312 -0.01915 
11/7/2016 20:21 312 -0.02075 
11/7/2016 20:26 312 -0.02095 
11/7/2016 20:31 312 -0.0228 
11/7/2016 20:36 312 -0.0207 
11/7/2016 20:41 312 -0.0215 
11/7/2016 20:46 312 -0.01995 
11/7/2016 20:51 312 -0.0209 
11/7/2016 20:56 312 -0.0202 
11/7/2016 21:01 312 -0.02125 
11/7/2016 21:06 312 -0.02045 
11/7/2016 21:11 312 -0.02345 
11/7/2016 21:16 312 -0.02325 
11/7/2016 21:21 312 -0.02195 
11/7/2016 21:26 312 -0.02065 
11/7/2016 21:31 312 -0.01935 
11/7/2016 21:36 312 -0.01475 
11/7/2016 21:41 312 -0.0172 
11/7/2016 21:46 312 -0.01635 
11/7/2016 21:51 312 -0.01495 
11/7/2016 21:56 312 -0.0145 
11/7/2016 22:01 312 -0.0177 
11/7/2016 22:06 312 -0.01585 
11/7/2016 22:11 312 -0.0134 
11/7/2016 22:16 312 -0.01355 
11/7/2016 22:21 312 -0.01435 
11/7/2016 22:26 312 -0.0134 
11/7/2016 22:31 312 -0.0157 
11/7/2016 22:36 312 -0.01535 
11/7/2016 22:41 312 -0.0139 
11/7/2016 22:46 312 -0.01495 
11/7/2016 22:51 312 -0.01585 
11/7/2016 22:56 312 -0.01735 
11/7/2016 23:01 312 -0.01475 
11/7/2016 23:06 312 -0.0165 
11/7/2016 23:11 312 -0.0157 
11/7/2016 23:16 312 -0.0223 
11/7/2016 23:21 312 -0.0214 
11/7/2016 23:26 312 -0.02155 
11/7/2016 23:31 312 -0.02245 
11/7/2016 23:36 312 -0.0223 
11/7/2016 23:41 312 -0.02315 
11/7/2016 23:46 312 -0.0204 
11/7/2016 23:51 312 -0.01915 
11/7/2016 23:56 312 -0.018 
11/8/2016 0:01 313 -0.01895 
11/8/2016 0:06 313 -0.0195 
11/8/2016 0:11 313 -0.0152 
11/8/2016 0:16 313 -0.0157 
11/8/2016 0:21 313 -0.0177 
11/8/2016 0:26 313 -0.0179 
11/8/2016 0:31 313 -0.0185 
11/8/2016 0:36 313 -0.0164 
11/8/2016 0:41 313 -0.0145 
11/8/2016 0:46 313 -0.0158 
11/8/2016 0:51 313 -0.01295 
11/8/2016 0:56 313 -0.0149 
11/8/2016 1:01 313 -0.014 
11/8/2016 1:06 313 -0.01505 
11/8/2016 1:11 313 -0.01795 
11/8/2016 1:16 313 -0.01375 
11/8/2016 1:21 313 -0.0066 
11/8/2016 1:26 313 -0.00835 
11/8/2016 1:31 313 -0.00785 
11/8/2016 1:36 313 -0.0082 
11/8/2016 1:41 313 -0.0108 
11/8/2016 1:46 313 -0.01275 
11/8/2016 1:51 313 -0.01515 
11/8/2016 1:56 313 -0.01505 
11/8/2016 2:01 313 -0.01805 
11/8/2016 2:06 313 -0.01875 
11/8/2016 2:11 313 -0.01955 
11/8/2016 2:16 313 -0.0201 
11/8/2016 2:21 313 -0.0183 
11/8/2016 2:26 313 -0.01715 
11/8/2016 2:31 313 -0.0169 
11/8/2016 2:36 313 -0.0139 
11/8/2016 2:41 313 -0.0145 
11/8/2016 2:46 313 -0.0162 
11/8/2016 2:51 313 -0.01275 
11/8/2016 2:56 313 -0.01285 
11/8/2016 3:01 313 -0.01605 
11/8/2016 3:06 313 -0.0133 
11/8/2016 3:11 313 -0.00905 
11/8/2016 3:16 313 -0.0149 
11/8/2016 3:21 313 -0.01395 
11/8/2016 3:26 313 -0.01115 
11/8/2016 3:31 313 -0.0108 
11/8/2016 3:36 313 -0.01015 
11/8/2016 3:41 313 -0.00805 
11/8/2016 3:46 313 -0.00735 
11/8/2016 3:51 313 -0.00615 
11/8/2016 3:56 313 -0.0055 
11/8/2016 4:01 313 -0.0138 
11/8/2016 4:06 313 -0.01405 
11/8/2016 4:11 313 -0.01755 
11/8/2016 4:16 313 -0.0181 
11/8/2016 4:21 313 -0.01675 
11/8/2016 4:26 313 -0.0165 
11/8/2016 4:31 313 -0.01455 
11/8/2016 4:36 313 -0.01425 
11/8/2016 4:41 313 -0.0146 
11/8/2016 4:46 313 -0.0152 
11/8/2016 4:51 313 -0.0125 
11/8/2016 4:56 313 -0.0117 
11/8/2016 5:01 313 -0.01215 
11/8/2016 5:06 313 -0.0125 
11/8/2016 5:11 313 -0.0132 
11/8/2016 5:16 313 -0.0126 
11/8/2016 5:21 313 -0.0135 
11/8/2016 5:26 313 -0.01165 
11/8/2016 5:31 313 -0.00775 
11/8/2016 5:36 313 -0.00695 
11/8/2016 5:41 313 -0.00385 
11/8/2016 5:46 313 -0.00235 
11/8/2016 5:51 313 0.0028 
11/8/2016 5:56 313 0.01585 
11/8/2016 6:01 313 0.03635 
11/8/2016 6:06 313 0.07065 
11/8/2016 6:11 313 0.1311 
11/8/2016 6:16 313 0.21305 
11/8/2016 6:21 313 0.32055 
11/8/2016 6:26 313 0.43565 
11/8/2016 6:31 313 0.5715 
11/8/2016 6:36 313 0.7204 
11/8/2016 6:41 313 0.8756 
11/8/2016 6:46 313 1.0433 
11/8/2016 6:51 313 1.2124 
11/8/2016 6:56 313 1.3829 
11/8/2016 7:01 313 1.5636 
11/8/2016 7:06 313 1.7513 
11/8/2016 7:11 313 1.9341 
11/8/2016 7:16 313 2.11025 
11/8/2016 7:21 313 2.28195 
11/8/2016 7:26 313 2.46095 
11/8/2016 7:31 313 2.64895 
11/8/2016 7:36 313 2.83475 
11/8/2016 7:41 313 3.01725 
11/8/2016 7:46 313 3.19545 
11/8/2016 7:51 313 3.37045 
11/8/2016 7:56 313 3.5479 
11/8/2016 8:01 313 3.71555 
11/8/2016 8:06 313 3.89685 
11/8/2016 8:11 313 4.0722 
11/8/2016 8:16 313 4.24365 
11/8/2016 8:21 313 4.421 
11/8/2016 8:26 313 4.6007 
11/8/2016 8:31 313 4.7579 
11/8/2016 8:36 313 4.9085 
11/8/2016 8:41 313 5.0742 
11/8/2016 8:46 313 5.2702 
11/8/2016 8:51 313 5.43175 
11/8/2016 8:56 313 5.5679 
11/8/2016 9:01 313 5.70595 
11/8/2016 9:06 313 5.8536 
11/8/2016 9:11 313 6.00405 
11/8/2016 9:16 313 6.14975 
11/8/2016 9:21 313 6.28225 
11/8/2016 9:26 313 6.3957 
11/8/2016 9:31 313 6.49145 
11/8/2016 9:36 313 6.61005 
11/8/2016 9:41 313 6.7059 
11/8/2016 9:46 313 6.803 
11/8/2016 9:51 313 6.9047 
11/8/2016 9:56 313 6.99005 
11/8/2016 10:01 313 7.10665 
11/8/2016 10:06 313 7.1775 
11/8/2016 10:11 313 7.24965 
11/8/2016 10:16 313 7.32285 
11/8/2016 10:21 313 7.40145 
11/8/2016 10:26 313 7.4465 
11/8/2016 10:31 313 7.48625 
11/8/2016 10:36 313 7.5403 
11/8/2016 10:41 313 7.56665 
11/8/2016 10:46 313 7.6129 
11/8/2016 10:51 313 7.6587 
11/8/2016 10:56 313 7.65805 
11/8/2016 11:01 313 7.69065 
11/8/2016 11:06 313 7.69305 
11/8/2016 11:11 313 7.75695 
11/8/2016 11:16 313 7.7813 
11/8/2016 11:21 313 7.807 
11/8/2016 11:26 313 7.84605 
11/8/2016 11:31 313 7.86405 
11/8/2016 11:36 313 7.86835 
11/8/2016 11:41 313 7.71245 
11/8/2016 11:46 313 7.81435 
11/8/2016 11:51 313 7.78805 
11/8/2016 11:56 313 7.7583 
11/8/2016 12:01 313 7.70065 
11/8/2016 12:06 313 7.6603 
11/8/2016 12:11 313 7.622 
11/8/2016 12:16 313 7.56315 
11/8/2016 12:21 313 7.4049 
11/8/2016 12:26 313 7.4034 
11/8/2016 12:31 313 7.278 
11/8/2016 12:36 313 7.3192 
11/8/2016 12:41 313 7.19265 
11/8/2016 12:46 313 7.4927 
11/8/2016 12:51 313 7.54555 
11/8/2016 12:56 313 7.69435 
11/8/2016 13:01 313 6.95105 
11/8/2016 13:06 313 6.26065 
11/8/2016 13:11 313 6.90735 
11/8/2016 13:16 313 6.4603 
11/8/2016 13:21 313 5.69755 
11/8/2016 13:26 313 5.30295 
11/8/2016 13:31 313 5.993 
11/8/2016 13:36 313 6.24425 
11/8/2016 13:41 313 5.89575 
11/8/2016 13:46 313 6.3803 
11/8/2016 13:51 313 6.17455 
11/8/2016 13:56 313 5.6555 
11/8/2016 14:01 313 5.0811 
11/8/2016 14:06 313 3.33805 
11/8/2016 14:11 313 3.131 
11/8/2016 14:16 313 3.87235 
11/8/2016 14:21 313 4.3724 
11/8/2016 14:26 313 4.6554 
11/8/2016 14:31 313 4.7956 
11/8/2016 14:36 313 3.41335 
11/8/2016 14:41 313 3.11155 
11/8/2016 14:46 313 3.9269 
11/8/2016 14:51 313 2.8726 
11/8/2016 14:56 313 2.68095 
11/8/2016 15:01 313 2.98235 
11/8/2016 15:06 313 3.1635 
11/8/2016 15:11 313 3.09815 
11/8/2016 15:16 313 2.89455 
11/8/2016 15:21 313 2.7253 
11/8/2016 15:26 313 2.52735 
11/8/2016 15:31 313 2.30685 
11/8/2016 15:36 313 1.9471 
11/8/2016 15:41 313 1.76245 
11/8/2016 15:46 313 1.7001 
11/8/2016 15:51 313 1.509 
11/8/2016 15:56 313 1.31435 
11/8/2016 16:01 313 1.1337 
11/8/2016 16:06 313 0.9801 
11/8/2016 16:11 313 0.83105 
11/8/2016 16:16 313 0.67265 
11/8/2016 16:21 313 0.53225 
11/8/2016 16:26 313 0.41065 
11/8/2016 16:31 313 0.3211 
11/8/2016 16:36 313 0.2437 
11/8/2016 16:41 313 0.1663 
11/8/2016 16:46 313 0.08585 
11/8/2016 16:51 313 0.02745 
11/8/2016 16:56 313 -0.001 
11/8/2016 17:01 313 -0.0124 
11/8/2016 17:06 313 -0.01965 
11/8/2016 17:11 313 -0.0209 
11/8/2016 17:16 313 -0.0219 
11/8/2016 17:21 313 -0.02165 
11/8/2016 17:26 313 -0.0221 
11/8/2016 17:31 313 -0.021 
11/8/2016 17:36 313 -0.02155 
11/8/2016 17:41 313 -0.0211 
11/8/2016 17:46 313 -0.0214 
11/8/2016 17:51 313 -0.0222 
11/8/2016 17:56 313 -0.0209 
11/8/2016 18:01 313 -0.0217 
11/8/2016 18:06 313 -0.0225 
11/8/2016 18:11 313 -0.0215 
11/8/2016 18:16 313 -0.02195 
11/8/2016 18:21 313 -0.0217 
11/8/2016 18:26 313 -0.02125 
11/8/2016 18:31 313 -0.02095 
11/8/2016 18:36 313 -0.0218 
11/8/2016 18:41 313 -0.02165 
11/8/2016 18:46 313 -0.02235 
11/8/2016 18:51 313 -0.0214 
11/8/2016 18:56 313 -0.0211 
11/8/2016 19:01 313 -0.02195 
11/8/2016 19:06 313 -0.02135 
11/8/2016 19:11 313 -0.02195 
11/8/2016 19:16 313 -0.0222 
11/8/2016 19:21 313 -0.0215 
11/8/2016 19:26 313 -0.02155 
11/8/2016 19:31 313 -0.0225 
11/8/2016 19:36 313 -0.02205 
11/8/2016 19:41 313 -0.0209 
11/8/2016 19:46 313 -0.0222 
11/8/2016 19:51 313 -0.02205 
11/8/2016 19:56 313 -0.02255 
11/8/2016 20:01 313 -0.0224 
11/8/2016 20:06 313 -0.0232 
11/8/2016 20:11 313 -0.0234 
11/8/2016 20:16 313 -0.02285 
11/8/2016 20:21 313 -0.0224 
11/8/2016 20:26 313 -0.0242 
11/8/2016 20:31 313 -0.023 
11/8/2016 20:36 313 -0.02055 
11/8/2016 20:41 313 -0.01945 
11/8/2016 20:46 313 -0.0173 
11/8/2016 20:51 313 -0.01545 
11/8/2016 20:56 313 -0.0199 
11/8/2016 21:01 313 -0.0195 
11/8/2016 21:06 313 -0.0178 
11/8/2016 21:11 313 -0.019 
11/8/2016 21:16 313 -0.0182 
11/8/2016 21:21 313 -0.01805 
11/8/2016 21:26 313 -0.01845 
11/8/2016 21:31 313 -0.018 
11/8/2016 21:36 313 -0.01645 
11/8/2016 21:41 313 -0.0161 
11/8/2016 21:46 313 -0.0163 
11/8/2016 21:51 313 -0.0157 
11/8/2016 21:56 313 -0.0152 
11/8/2016 22:01 313 -0.01885 
11/8/2016 22:06 313 -0.01865 
11/8/2016 22:11 313 -0.0191 
11/8/2016 22:16 313 -0.02055 
11/8/2016 22:21 313 -0.023 
11/8/2016 22:26 313 -0.0216 
11/8/2016 22:31 313 -0.0174 
11/8/2016 22:36 313 -0.0206 
11/8/2016 22:41 313 -0.0196 
11/8/2016 22:46 313 -0.0185 
11/8/2016 22:51 313 -0.02025 
11/8/2016 22:56 313 -0.0187 
11/8/2016 23:01 313 -0.0197 
11/8/2016 23:06 313 -0.01915 
11/8/2016 23:11 313 -0.0192 
11/8/2016 23:16 313 -0.01875 
11/8/2016 23:21 313 -0.0168 
11/8/2016 23:26 313 -0.01535 
11/8/2016 23:31 313 -0.01515 
11/8/2016 23:36 313 -0.0156 
11/8/2016 23:41 313 -0.01725 
11/8/2016 23:46 313 -0.0175 
11/8/2016 23:51 313 -0.0183 
11/8/2016 23:56 313 -0.01815 
11/9/2016 0:01 314 -0.02115 
11/9/2016 0:06 314 -0.01925 
11/9/2016 0:11 314 -0.01605 
11/9/2016 0:16 314 -0.01725 
11/9/2016 0:21 314 -0.01875 
11/9/2016 0:26 314 -0.01695 
11/9/2016 0:31 314 -0.01585 
11/9/2016 0:36 314 -0.0156 
11/9/2016 0:41 314 -0.0158 
11/9/2016 0:46 314 -0.01735 
11/9/2016 0:51 314 -0.02115 
11/9/2016 0:56 314 -0.0203 
11/9/2016 1:01 314 -0.01595 
11/9/2016 1:06 314 -0.0162 
11/9/2016 1:11 314 -0.01845 
11/9/2016 1:16 314 -0.01935 
11/9/2016 1:21 314 -0.01705 
11/9/2016 1:26 314 -0.01725 
11/9/2016 1:31 314 -0.0183 
11/9/2016 1:36 314 -0.01585 
11/9/2016 1:41 314 -0.01665 
11/9/2016 1:46 314 -0.0179 
11/9/2016 1:51 314 -0.02015 
11/9/2016 1:56 314 -0.01765 
11/9/2016 2:01 314 -0.016 
11/9/2016 2:06 314 -0.01575 
11/9/2016 2:11 314 -0.01795 
11/9/2016 2:16 314 -0.0155 
11/9/2016 2:21 314 -0.01745 
11/9/2016 2:26 314 -0.0203 
11/9/2016 2:31 314 -0.0185 
11/9/2016 2:36 314 -0.0186 
11/9/2016 2:41 314 -0.01935 
11/9/2016 2:46 314 -0.0184 
11/9/2016 2:51 314 -0.01735 
11/9/2016 2:56 314 -0.01695 
11/9/2016 3:01 314 -0.01775 
11/9/2016 3:06 314 -0.019 
11/9/2016 3:11 314 -0.0167 
11/9/2016 3:16 314 -0.015 
11/9/2016 3:21 314 -0.01565 
11/9/2016 3:26 314 -0.0153 
11/9/2016 3:31 314 -0.0167 
11/9/2016 3:36 314 -0.0172 
11/9/2016 3:41 314 -0.0183 
11/9/2016 3:46 314 -0.0197 
11/9/2016 3:51 314 -0.01745 
11/9/2016 3:56 314 -0.019 
11/9/2016 4:01 314 -0.0172 
11/9/2016 4:06 314 -0.0192 
11/9/2016 4:11 314 -0.018 
11/9/2016 4:16 314 -0.016 
11/9/2016 4:21 314 -0.01565 
11/9/2016 4:26 314 -0.01495 
11/9/2016 4:31 314 -0.0141 
11/9/2016 4:36 314 -0.0165 
11/9/2016 4:41 314 -0.0181 
11/9/2016 4:46 314 -0.0142 
11/9/2016 4:51 314 -0.014 
11/9/2016 4:56 314 -0.0154 
11/9/2016 5:01 314 -0.01815 
11/9/2016 5:06 314 -0.01695 
11/9/2016 5:11 314 -0.01535 
11/9/2016 5:16 314 -0.0173 
11/9/2016 5:21 314 -0.0168 
11/9/2016 5:26 314 -0.01705 
11/9/2016 5:31 314 -0.0131 
11/9/2016 5:36 314 -0.01255 
11/9/2016 5:41 314 -0.011 
11/9/2016 5:46 314 -0.0074 
11/9/2016 5:51 314 -0.0033 
11/9/2016 5:56 314 0.0092 
11/9/2016 6:01 314 0.02835 
11/9/2016 6:06 314 0.05945 
11/9/2016 6:11 314 0.11275 
11/9/2016 6:16 314 0.19305 
11/9/2016 6:21 314 0.29155 
11/9/2016 6:26 314 0.41715 
11/9/2016 6:31 314 0.5569 
11/9/2016 6:36 314 0.7058 
11/9/2016 6:41 314 0.85515 
11/9/2016 6:46 314 1.0122 
11/9/2016 6:51 314 1.17105 
11/9/2016 6:56 314 1.3468 
11/9/2016 7:01 314 1.533 
11/9/2016 7:06 314 1.72655 
11/9/2016 7:11 314 1.8999 
11/9/2016 7:16 314 2.0892 
11/9/2016 7:21 314 2.27335 
11/9/2016 7:26 314 2.45275 
11/9/2016 7:31 314 2.6254 
11/9/2016 7:36 314 2.80495 
11/9/2016 7:41 314 2.9698 
11/9/2016 7:46 314 3.14485 
11/9/2016 7:51 314 3.33695 
11/9/2016 7:56 314 3.5185 
11/9/2016 8:01 314 3.72455 
11/9/2016 8:06 314 3.91035 
11/9/2016 8:11 314 4.0785 
11/9/2016 8:16 314 4.2559 
11/9/2016 8:21 314 4.4217 
11/9/2016 8:26 314 4.5722 
11/9/2016 8:31 314 4.7556 
11/9/2016 8:36 314 4.9501 
11/9/2016 8:41 314 5.11165 
11/9/2016 8:46 314 5.2733 
11/9/2016 8:51 314 5.4304 
11/9/2016 8:56 314 5.56685 
11/9/2016 9:01 314 5.703 
11/9/2016 9:06 314 5.8769 
11/9/2016 9:11 314 6.01635 
11/9/2016 9:16 314 6.111 
11/9/2016 9:21 314 6.24235 
11/9/2016 9:26 314 6.3809 
11/9/2016 9:31 314 6.5062 
11/9/2016 9:36 314 6.64785 
11/9/2016 9:41 314 6.75385 
11/9/2016 9:46 314 6.84935 
11/9/2016 9:51 314 6.93285 
11/9/2016 9:56 314 7.02905 
11/9/2016 10:01 314 7.11505 
11/9/2016 10:06 314 7.2036 
11/9/2016 10:11 314 7.2851 
11/9/2016 10:16 314 7.33835 
11/9/2016 10:21 314 7.44855 
11/9/2016 10:26 314 7.4837 
11/9/2016 10:31 314 7.53375 
11/9/2016 10:36 314 7.62295 
11/9/2016 10:41 314 7.66075 
11/9/2016 10:46 314 7.68485 
11/9/2016 10:51 314 7.7384 
11/9/2016 10:56 314 7.7615 
11/9/2016 11:01 314 7.82885 
11/9/2016 11:06 314 7.8675 
11/9/2016 11:11 314 7.91915 
11/9/2016 11:16 314 7.94695 
11/9/2016 11:21 314 7.93695 
11/9/2016 11:26 314 7.9442 
11/9/2016 11:31 314 7.9382 
11/9/2016 11:36 314 7.9218 
11/9/2016 11:41 314 7.92835 
11/9/2016 11:46 314 7.9046 
11/9/2016 11:51 314 7.8732 
11/9/2016 11:56 314 7.83255 
11/9/2016 12:01 314 7.803 
11/9/2016 12:06 314 7.7647 
11/9/2016 12:11 314 7.7232 
11/9/2016 12:16 314 7.6825 
11/9/2016 12:21 314 7.6342 
11/9/2016 12:26 314 7.5411 
11/9/2016 12:31 314 7.45375 
11/9/2016 12:36 314 7.38675 
11/9/2016 12:41 314 7.18185 
11/9/2016 12:46 314 7.13925 
11/9/2016 12:51 314 7.135 
11/9/2016 12:56 314 6.98295 
11/9/2016 13:01 314 6.89455 
11/9/2016 13:06 314 6.8586 
11/9/2016 13:11 314 6.7578 
11/9/2016 13:16 314 6.65955 
11/9/2016 13:21 314 6.57115 
11/9/2016 13:26 314 6.442 
11/9/2016 13:31 314 6.2897 
11/9/2016 13:36 314 6.1718 
11/9/2016 13:41 314 6.0275 
11/9/2016 13:46 314 5.88025 
11/9/2016 13:51 314 5.73785 
11/9/2016 13:56 314 5.5934 
11/9/2016 14:01 314 5.4494 
11/9/2016 14:06 314 5.1863 
11/9/2016 14:11 314 4.98255 
11/9/2016 14:16 314 4.8496 
11/9/2016 14:21 314 4.8176 
11/9/2016 14:26 314 4.6013 
11/9/2016 14:31 314 4.2561 
11/9/2016 14:36 314 3.96345 
11/9/2016 14:41 314 3.9824 
11/9/2016 14:46 314 3.9432 
11/9/2016 14:51 314 3.7544 
11/9/2016 14:56 314 3.4839 
11/9/2016 15:01 314 2.7597 
11/9/2016 15:06 314 2.4419 
11/9/2016 15:11 314 2.64675 
11/9/2016 15:16 314 2.45525 
11/9/2016 15:21 314 2.4179 
11/9/2016 15:26 314 2.3876 
11/9/2016 15:31 314 2.23465 
11/9/2016 15:36 314 2.07505 
11/9/2016 15:41 314 1.79335 
11/9/2016 15:46 314 1.415 
11/9/2016 15:51 314 1.25875 
11/9/2016 15:56 314 0.99305 
11/9/2016 16:01 314 0.716 
11/9/2016 16:06 314 0.51725 
11/9/2016 16:11 314 0.43155 
11/9/2016 16:16 314 0.42175 
11/9/2016 16:21 314 0.52755 
11/9/2016 16:26 314 0.4067 
11/9/2016 16:31 314 0.2853 
11/9/2016 16:36 314 0.18875 
11/9/2016 16:41 314 0.1121 
11/9/2016 16:46 314 0.0422 
11/9/2016 16:51 314 0.0087 
11/9/2016 16:56 314 -0.01395 
11/9/2016 17:01 314 -0.0253 
11/9/2016 17:06 314 -0.03095 
11/9/2016 17:11 314 -0.03115 
11/9/2016 17:16 314 -0.0322 
11/9/2016 17:21 314 -0.03055 
11/9/2016 17:26 314 -0.02585 
11/9/2016 17:31 314 -0.02525 
11/9/2016 17:36 314 -0.0207 
11/9/2016 17:41 314 -0.01985 
11/9/2016 17:46 314 -0.0202 
11/9/2016 17:51 314 -0.0216 
11/9/2016 17:56 314 -0.02065 
11/9/2016 18:01 314 -0.02215 
11/9/2016 18:06 314 -0.02005 
11/9/2016 18:11 314 -0.017 
11/9/2016 18:16 314 -0.01985 
11/9/2016 18:21 314 -0.02015 
11/9/2016 18:26 314 -0.02005 
11/9/2016 18:31 314 -0.01875 
11/9/2016 18:36 314 -0.019 
11/9/2016 18:41 314 -0.01875 
11/9/2016 18:46 314 -0.0196 
11/9/2016 18:51 314 -0.
11/9/2016 18:56 314 -0.01185 
11/9/2016 19:01 314 -0.01485 
11/9/2016 19:06 314 -0.0187 
11/9/2016 19:11 314 -0.02015 
11/9/2016 19:16 314 -0.01935 
11/9/2016 19:21 314 -0.0197 
11/9/2016 19:26 314 -0.01885 
11/9/2016 19:31 314 -0.0218 
11/9/2016 19:36 314 -0.0169 
11/9/2016 19:41 314 -0.01205 
11/9/2016 19:46 314 -0.01245 
11/9/2016 19:51 314 -0.0112 
11/9/2016 19:56 314 -0.01655 
11/9/2016 20:01 314 -0.0185 
11/9/2016 20:06 314 -0.0204 
11/9/2016 20:11 314 -0.0227 
11/9/2016 20:16 314 -0.02115 
11/9/2016 20:21 314 -0.01345 
11/9/2016 20:26 314 -0.0135 
11/9/2016 20:31 314 -0.0191 
11/9/2016 20:36 314 -0.0172 
11/9/2016 20:41 314 -0.0136 
11/9/2016 20:46 314 -0.0129 
11/9/2016 20:51 314 -0.0176 
11/9/2016 20:56 314 -0.01285 
11/9/2016 21:01 314 -0.0138 
11/9/2016 21:06 314 -0.0179 
11/9/2016 21:11 314 -0.0193 
11/9/2016 21:16 314 -0.02365 
11/9/2016 21:21 314 -0.02045 
11/9/2016 21:26 314 -0.0218 
11/9/2016 21:31 314 -0.0215 
11/9/2016 21:36 314 -0.02105 
11/9/2016 21:41 314 -0.0184 
11/9/2016 21:46 314 -0.01795 
11/9/2016 21:51 314 -0.01945 
11/9/2016 21:56 314 -0.01865 
11/9/2016 22:01 314 -0.01425 
11/9/2016 22:06 314 -0.0125 
11/9/2016 22:11 314 -0.0093 
11/9/2016 22:16 314 -0.01355 
11/9/2016 22:21 314 -0.
11/9/2016 22:26 314 -0.01205 
11/9/2016 22:31 314 -0.01225 
11/9/2016 22:36 314 -0.0138 
11/9/2016 22:41 314 -0.01255 
11/9/2016 22:46 314 -0.01655 
11/9/2016 22:51 314 -0.01695 
11/9/2016 22:56 314 -0.01605 
11/9/2016 23:01 314 -0.018 
11/9/2016 23:06 314 -0.01165 
11/9/2016 23:11 314 -0.00995 
11/9/2016 23:16 314 -0.0181 
11/9/2016 23:21 314 -0.0137 
11/9/2016 23:26 314 -0.014 
11/9/2016 23:31 314 -0.02185 
11/9/2016 23:36 314 -0.0238 
11/9/2016 23:41 314 -0.02165 
11/9/2016 23:46 314 -0.02095 
11/9/2016 23:51 314 -0.01925 
11/9/2016 23:56 314 -0.0201 
+0

請使這種可重複性,否則它將是非常困難的人來幫助你。 – Axeman

+0

我在前幾天添加了數據。還有什麼會有用的嗎?這是我第一次在這裏發帖,所以任何指針都是值得歡迎的。 – Isaac

+1

粘貼在'dput()'的輸出中發佈你的數據。這樣,我們將擁有一個與您的實際數據框完全相同結構的數據框。例如,要發佈數據的前40行,請粘貼'dput(original_data [1:40,])'的輸出。 – eipi10

回答

2

TL; DR:這看起來像一個時區的問題。將日期轉換爲POSIXct時,默認時區是您的本地時區。但是,當您在ggplot內運行date_format()時,日期在繪圖之前會轉換爲GMT,所以時間將全部移位GMT與當地時區之間的差異。要獲得正確的小時繪圖,您可以在date_format之內明確設置所需的時區,或者在將Date轉換爲POSIXct時,您可以明確地將時區設置爲GMT。


在編寫ggplot代碼之前,讓我們來看看您的數據。下面,我已經開始與您的數據Date到POSIXct轉換前:

head(original_data) 
str(original_data) 
  Date DOY Reference 
1 11/7/2016 0:01 312 -0.01370 
2 11/7/2016 0:06 312 -0.01525 
3 11/7/2016 0:11 312 -0.01325 
4 11/7/2016 0:16 312 -0.
5 11/7/2016 0:21 312 -0.01190 
6 11/7/2016 0:26 312 -0.01120 

'data.frame': 864 obs. of 3 variables: 
$ Date  : chr "11/7/2016 0:01" "11/7/2016 0:06" "11/7/2016 0:11" "11/7/2016 0:16" ... 
$ DOY  : int 312 312 312 312 312 312 312 312 312 312 ... 
$ Reference: num -0.0137 -0.0152 -0.0132 -0.-0.0119 ... 

現在讓我們轉換Date到POSIXct兩種不同的方式:首先,如果沒有設置時區,然後將時區設置爲GMT。需要注意的是Date1是在我的本地時區(美國太平洋),而Date2爲GMT,雖然字面時間字符串是相同的:

original_data$Date1 <- as.POSIXct(x = original_data$Date, format = "%m/%d/%Y %H:%M") 
original_data$Date2 <- as.POSIXct(x = original_data$Date, format = "%m/%d/%Y %H:%M", tz="GMT") 

head(original_data$Date1) 
[1] "2016-11-07 00:01:00 PST" "2016-11-07 00:06:00 PST" "2016-11-07 00:11:00 PST" "2016-11-07 00:16:00 PST" 
[5] "2016-11-07 00:21:00 PST" "2016-11-07 00:26:00 PST" 
head(original_data$Date2) 
[1] "2016-11-07 00:01:00 GMT" "2016-11-07 00:06:00 GMT" "2016-11-07 00:11:00 GMT" "2016-11-07 00:16:00 GMT" 
[5] "2016-11-07 00:21:00 GMT" "2016-11-07 00:26:00 GMT" 

以下是date_format函數的代碼。請注意,默認tz(時區)設置爲UTC,與GMT相同。所以date_format正轉向從你的數據的時區時間值GMT:

date_format 
function (format = "%Y-%m-%d", tz = "UTC") 
{ 
    function(x) format(x, format, tz = tz) 
} 

現在對於ggplot:首先,我們將與Date1工作。在下面的例子中,請注意,當我們使用默認日期格式時,小時數是正確的。然而,當我們使用scale_x_datetime而沒有指定時區時,它看起來像ggplot正在從我當地的時區(美國太平洋)轉移到8小時後的GMT。但是,當我在date_format()中指定「America/Los_Angeles」時區時,我會得到所需的小時值。

# Create plot with Date1, but without scale_x_datetime 
p = ggplot(original_data, aes(Date1, Reference)) + 
    facet_wrap(~ DOY, scales="free_x") + 
    xlab("Time (hours)") + 
    geom_point() +  
    ylab(expression(Radiation ~ (W ~ m^{-2}))) + 
    ggtitle("Calibration Plots") + 
    theme_bw() + 
    theme(axis.title=element_text(size=12,face="bold"), 
     title = element_text(size=9, face = "bold")) 

p + scale_x_datetime(date_breaks = "3 hours") + 
    ggtitle("Default date formatting") + 
    theme(axis.text.x=element_text(size=9, angle=-90, , vjust=0.5)) 
p + scale_x_datetime(date_breaks = "3 hours", labels=date_format("%H")) + 
    ggtitle('date_format("%H")') 
p + scale_x_datetime(date_breaks = "3 hours", labels=date_format("%H", tz="America/Los_Angeles")) + 
    ggtitle('date_format("%H", tz="America/Los_Angeles")') 

enter image description here

在另一方面,如果我們使用Date2,它已經被設置爲GMT時區,那麼我們就不需要內date_format()指定時區:

# Create plot with Date2, but without scale_x_datetime 
p = ggplot(original_data, aes(Date2, Reference)) + 
    facet_wrap(~ DOY, scales="free_x") + 
    xlab("Time (hours)") + 
    geom_point() +  
    ylab(expression(Radiation ~ (W ~ m^{-2}))) + 
    ggtitle("Calibration Plots") + 
    theme_bw() + 
    theme(axis.title=element_text(size=12,face="bold"), 
     title = element_text(size=9, face = "bold")) 

p + scale_x_datetime(date_breaks = "3 hours") + 
    ggtitle("Default date formatting") + 
    theme(axis.text.x=element_text(size=9, angle=-90, , vjust=0.5)) 
p + scale_x_datetime(date_breaks = "3 hours", labels=date_format("%H")) + 
    ggtitle('date_format("%H")') 
p + scale_x_datetime(date_breaks = "3 hours", labels=date_format("%H", tz="GMT")) + 
    ggtitle('date_format("%H", tz="GMT")') 

enter image description here

+0

非常全面的答案。另請注意,「scale _ * _ datetime()'現在支持時區,它將默認使用附加到變量的時區,但可以使用'timezone'參數覆蓋。 (來自NEWS。) – Axeman

+0

謝謝!這是非常清晰和徹底。我真的很感激你花時間來引導我爲什麼會發生這種情況以及修復它的選項。 – Isaac

+1

@Axeman,謝謝你讓我知道,因爲我沒有意識到這一點(我猜我沒有跟上最新的ggplot2新聞,我也應該)。艾薩克,不客氣! – eipi10