2013-04-25 107 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绘图教程,其中有足够多的。