1

我有以下数据框。时隙之间的差距是不同的,有时小,有时大:

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') 

正如您在情节中看到的那样,我想在短时间跨度之间获得良好的分离 在此处输入图像描述

4

2 回答 2

2

我将xts用于时间序列,并使用quantmod来生成(我认为)您想要的图表类型。(我也尽可能避免POSIXlt,因为它比 更慢并且使用更多内存POSIXct

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

在此处输入图像描述

还有. chart_Series_chartSeries

或者,您可以直接使用 xts 的axTicksByTime函数,但 x 轴的格式不会那么好。

plot(head(axTicksByTime(x), -1), log(x), type="l", col="red")
于 2013-04-26T14:39:47.403 回答
0

type='l'表示情节的类型是线。所以它向你显示了一条线......你可能想要type = 'p',那就是点。

在此处查看更多信息并查看一些 R 绘图教程,它们的数量已经足够多了。

于 2013-04-25T22:14:10.130 回答