Rquantmod chartSeries:向图表添加两个时间序列

问题描述 投票:0回答:1

我使用Quantmod的chartSeries和chart_Series函数,试图在单个图表上绘制两个时间序列。以下代码在图表输出中产生了一个绿色的粗带。我了解这是因为我将其绑定并为每个观察结果显示两个值。但是,我无法弄清楚如何分别显示两个时间序列。

如果无法通过Quantmod函数执行此操作,是否可以在ggplot中执行?

library(quantmod)

getSymbols(c('VXX','^VIX'), from = "2019-01-01", to = "2020-03-16")

symbols <- c(VIX$VIX.Adjusted,VXX$VXX.Adjusted)

chartSeries(symbols)
r charts finance quantmod
1个回答
0
投票

[有些软件包比使用quantmod中的chartSeries容易一些。

包rtsplot。使用基本R绘图功能进行时间​​序列绘图。阅读帮助PDF中的所有选项。

library(rtsplot)
rtsplot(VIX)
rtsplot.lines(VXX$VXX.Adjusted)

或者如果要使用ggplot2,则可以使用tidyquant。 tidyquant还向ggplot2添加了烛台图表选项。阅读小插图以获取更多信息:

library(tidyquant)
library(ggplot2)
vols <- tq_get(c('VXX','^VIX'), from = "2019-01-01", to = "2020-03-16") 

vols %>% 
  ggplot(aes(x = date, y = adjusted,  group = symbol)) +
  geom_line() +
  theme_tq()
© www.soinside.com 2019 - 2024. All rights reserved.