2013-04-25 93 views
1

我有以下數據框。時隙之間的差距是不同的,有時小,有時大:R繪圖時間序列數據:極短時間段

history <- structure(list(timestamp = structure(1:13, .Label = c("2006-06-11 04:43:56", 
"2006-06-11 04:47:24", "2006-06-11 04:47:54", "2006-06-11 04:49:37", 
"2006-06-11 04:52:12", "2006-06-11 04:58:22", "2006-06-11 05:01:11", 
"2006-06-11 05:06:56", "2006-06-11 05:14:35", "2006-06-11 05:21:44", 
"2006-08-21 19:55:50", "2006-08-21 19:56:31", "2007-11-22 22:09:17" 
), class = "factor"), page_length = c(1753, 146, 2401, 461, 113, 
1248, 1268, 720, 1290, 436, 531, 502, 746)), .Names = c("timestamp", 
"page_length"), row.names = c(NA, -13L), class = "data.frame") 

history 
#    timestamp page_length 
#1 2006-06-11 04:43:56  1753 
#2 2006-06-11 04:47:24   146 
#3 2006-06-11 04:47:54  2401 
#4 2006-06-11 04:49:37   461 
#5 2006-06-11 04:52:12   113 
#6 2006-06-11 04:58:22  1248 
#7 2006-06-11 05:01:11  1268 
#8 2006-06-11 05:06:56   720 
#9 2006-06-11 05:14:35  1290 
#10 2006-06-11 05:21:44   436 
#11 2006-08-21 19:55:50   531 
#12 2006-08-21 19:56:31   502 
#13 2007-11-22 22:09:17   746 

但我遇到的問題是,當我用下面的方法來繪製我沒有得到時間之間的明確分工。

plot(as.POSIXlt(history$timestamp,format='%Y-%m-%d %H:%M:%S'), 
    log(history$page_length), xlab= "Months", ylab= "log page Length", type='l', col='red') 

正如你在劇情看,我想短的時間跨度之間的良好分離 enter image description here

+0

其實,這個問題是StackOverflow的更合適,因爲它是關於節目。 – sashkello 2013-04-25 22:15:13

回答

2

我用xts時間序列,我用quantmod生產圖的是(我覺得)你想要的類型。 (我也避免POSIXlt時可能的,因爲它是速度較慢,並使用更多的內存比POSIXct

library(quantmod) 
x <- xts(history[, 2], as.POSIXct(history[, 1])) 
chartSeries(log(x), theme="white") 

enter image description here

還有chart_Series,但目前,它是無證,比chartSeries欠發達。

或者,您可以直接使用xts的axTicksByTime函數,但x軸的格式不會很好。

plot(head(axTicksByTime(x), -1), log(x), type="l", col="red") 
0

type='l'指劇情的類型是線。所以它顯示你一條線......你可能想要type = 'p',那就是點。

查看更多信息here並查看一些R繪圖教程,其中有足夠多的。