【发布时间】:2016-10-12 23:13:54
【问题描述】:
我正在准备一个菜单,该菜单与生成图形相关,其中源是 xts 对象和 3 个 TTR 指标。似乎捆绑在 chartSeries 线周围的“if - 语句”使得并非所有指标都可见。目前即使改变指标的顺序,结果也只显示图表线最末端的指标。
下面是我在 R-Studio 中运行的代码。
########################################################
# 1. Create a minimal df
########################################################
date <- as.Date(c("2015-10-11", "2016-11-11", "2017-12-11"))
o <- c(1459.60, 1458.47, 1457.71)
c <- c(1458.44, 1457.68, 1458.27)
h <- c(1459.76, 1459.01, 1458.27)
l <- c(1458.08, 1457.52, 1457.70)
v <- c(185, 24080, 9503)
a <- c(185, 24080, 9503)
d3 <- data.frame(date,o,c,h,l,v,a)
colnames(d3)[1:7] <- c('date', 'open', 'close', 'high', 'low', 'volume', 'adjusted')
########################################################
# 2. Produce an xts(x3) based on a df (d3)
########################################################
x3 <- xts(d3[,-1], order.by = d3$date)
########################################################
# 3. Extraction of menu, to select 1 which should
# create a graph with 3 indicators
########################################################
cat("\014")
menu.level.1 <- readline(prompt="Please select just number 1: ")
if (menu.level.1 == 1) {
print("...create graph")
chartSeries(x3); addRSI(1); addMACD(2, 1, 1); addBBands(2)
}
【问题讨论】:
标签: r menu rstudio xts quantmod