![](/img/trans.png)
[英]R quantmod chartSeries: Add multiple TA overlay to single chart
[英]R quantmod chartSeries: Add two time series to chart
使用 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)
有跡象表明,使它比使用更容易一點了幾包chartSeries
從quantmod。
包 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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.