0

我正在尝试使用 PerformanceAnalytics 库中的 chart.TimeSeries 在时间序列数据集上绘制各种事件。我试图遵循示例,但我认为我遗漏了一些东西。 ExampleChart我的 图表

我的垂直事件线和我的周期区域都没有显示在图表上。我的代码几乎与示例代码相同。有任何想法吗?

risk.dates = c(
  "2015-04-19"
  )
risk.labels = c(
  "Jon Oliver's Patent Episode "
  )

cycle.dates <- c ("2015-1-01/2015-01-31",
                      "2015-03-01/2015-03-31",
                      "2015-05-01/2015-05-31",
                      "2015-07-01/2015-07-31"
                      )
chart.TimeSeries(df, colorset = "darkblue",
                 date.format.in = "%Y-%m-%d",
                 legend.loc = NULL,
                 period.areas = cycles.dates,
                 period.color = "lightblue",
                 event.lines = risk.dates,
                 event.labels = risk.labels,
                 event.color = "red", lwd = 2,
                 main = "Reddit Sentiment Index",
                 auto.grid = FALSE)

df <- data.frame(DateTime=
          c("2/17/2015","2/18/2015","2/19/2015",
            "2/20/2015","2/21/2015","2/22/2015", 
            "2/23/2015","2/24/2015","2/25/2015",
            "2/26/2015","2/27/2015","2/28/2015",
            "2/28/2015","2/27/2015"),
           AvgSentimentScore=
             c("NA","NA","NA","NA","NA","NA","NA","NA","NA",
               "8.405975696","8.313470536","8.414560335",
                "8.720865075","9.284902246"))
4

0 回答 0