【问题标题】:Plotting subset of a time series in R在 R 中绘制时间序列的子集
【发布时间】: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&lt;-read.csv("C:/Users/A596741/Dropbox/edu/DBA/workspace/SMAnalysis/data/Tweets/time series/Apple tot unclassified.csv") attach(Tweets) head(Tweets) timeseries &lt;- ts(Tweets, start=c(2015, 1), frequency=42) head(timeseries) timeseries.sub &lt;- 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


【解决方案1】:

我得到了它的工作,现在一切都很好。干杯

【讨论】:

    猜你喜欢
    • 2018-01-23
    • 2020-04-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多