2014-02-28 38 views
2

我有以下的数据帧:剧情时间序列(24小时)中的R

> head(my[,1:2]) 
      Time TD_Wait 
96 18:24:45.776 12442 
97 18:24:53.798 26799 
1944 19:10:32.963 14423 
1945 19:10:34.709 13592 
1946 19:10:38.056 13457 
1947 19:10:38.281 14063 

> str(my) 
'data.frame': 25007 obs. of 2 variables: 
$ Time : Factor w/ 253251 levels "00:00:00.586",..: 27991 28001 33296 33306 33319 33320 33341 33363 33383 33392 ... 
$ TD_Wait: int 12442 26799 14423 13592 13457 14063 11717 10026 10590 19372 ... 

我无法格式化在X轴的时间标记,当我尝试

ggplot(data=my, aes(x=my$Time,y=TD_Wait/1000)) + geom_point() 

因为所有的时间都是相互重叠的。我很困惑如何继续这个。我试图改变时间的因素,但没有得到它。

有没有办法在24小时内按小时显示X轴上的时间标签?

回答

4

转换为第一POSIXct:

my$Time <- as.POSIXct(my$Time, format="%H:%M:%S") 
ggplot(data=my, aes(x=my$Time,y=TD_Wait/1000)) + geom_point() 

enter image description here

ggplot负责剩下的照顾。

+0

真棒,我这么笨我与POSIXct玩弄但是不成功....非常感谢你@BrodieG – user3006691

+0

@ user3006691,很高兴这有助于。如果这回答你的问题,请考虑将其标记为已回答。 – BrodieG

+0

完成并再次感谢:)! – user3006691

1

这是base图形方法。如图所示,您可以使用axis.POSIXctaxis.Date绘制POSIX*Date轴。

d <- read.table(text='Time TD_Wait 
18:24:45.776 12442 
18:24:53.798 26799 
19:10:32.963 14423 
19:10:34.709 13592 
19:10:38.056 13457 
19:10:38.281 14063', header=TRUE) 

d$Time <- as.POSIXct(d$Time, format="%H:%M:%S") 
plot(d$Time, d$TD_Wait/1000, xaxt='n', pch=20, las=1, 
    xlab='Time', ylab='TD_Wait/1000') 
axis.POSIXct(1, d$Time, format="%H:%M:%S") 

enter image description here