【发布时间】:2016-07-19 07:48:07
【问题描述】:
我在 R 中有一个时间序列。当我将它作为一个整体绘制时,我得到了预期的 4 个折线图,但第 4 个折线图是时间。
timeseries <- ts(Tweets, start=c(2015, 1), frequency=42)
head(timeseries)
plot(timeseries, plot.type = "multiple", lty = 1:2, cex = .8, col = "red", main = "Time series plot of Apple frequencies")
现在我只想打印三个折线图的一个子集,而没有日期作为折线图。当我创建一个子集时,它只绘制一个带有三条奇怪线的折线图
timeseries.sub <- timeseries[1:nrow(timeseries) - 1, c(1, 2, 3)]
plot(timeseries.sub, lty = 1:2, col = "red", xlab = "Time", type="l", main = "Time series plot of Apple frequencies")
如何在 x 轴上绘制这个时间序列,而不是第四个折线图?我在这里找到了很多例子,但没有一个真正有效。 谢谢彼得
【问题讨论】:
-
你能提供一个你正在使用的数据框的例子吗?
-
这里是相关代码:
Tweets<-read.csv("C:/Users/A596741/Dropbox/edu/DBA/workspace/SMAnalysis/data/Tweets/time series/Apple tot unclassified.csv") attach(Tweets) head(Tweets) timeseries <- ts(Tweets, start=c(2015, 1), frequency=42) head(timeseries) timeseries.sub <- timeseries[1:nrow(timeseries) - 1, c(1, 2, 3)] plot(timeseries.sub, lty = 1:2, col = "red", xlab = "Time", type="l", main = "Time series plot of Apple frequencies")注意是库存数据,所以只使用工作日,没有周末。谢谢你。彼得 -
数据如下: > head(Tweets) date Apple open close 1 02.11.2015 1352 119.87 121.18 2 03.11.2015 1501 120.79 122.57 .... > head(timeseries) date Apple open close [ 1,] 2 1352 119.87 121.18 [2,] 4 1501 120.79 122.57
标签: r plot time-series