- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个高级问题。
我为 chartSeries quantmod 函数使用我自己的布局,我什至可以创建我自己的 newTA。一切正常。但是……
我想做却做不到的事:
a) 处理 3 个图表中每个图表的图例: - 移动到另一个角落,(从“topleft”到“topright”) - 更改内容 - 如果需要完全删除......
b) 我的指标生成 2 个图例: 值(value)1 值2 同上...我该如何修改它们?我怎样才能删除它们?
c) 控制yaxis的位置和范围(放在左边/右边 甚至删除它们 图上有副轴时也是如此
d) 修改主图例(右上角那个 日期范围写在哪里
一个有效的示例代码:
# Load Library
library(quantmod)
# Get Data
getSymbols("SPY", src="yahoo", from = "2010-01-01")
# Create my indicator (30 values)
value1 <- rnorm(30, mean = 50, sd = 25)
value2 <- rnorm(30, mean = 50, sd = 25)
# merge with the first 30 rows of SPY
dataset <- merge(first(SPY, n = 30),
value1,
value2)
# **** data has now 8 columns:
# - Open
# - High
# - Low
# - Close
# - Volume
# - Adjusted
# - a (my indicator value 1)
# - b (my indicator value 2)
#
# create my TA function - This could also be achieve using the preFUN option of newTA
myTAfun <- function(a){
# input: a: function will receive whole dataset
a[,7:8] # just return my indicator values
}
# create my indicator to add to chartSeries
newMyTA <- newTA(FUN = myTAfun, # chartSeries will pass whole dataset,
# I just want to process the last 2 columns
lty = c("solid", "dotted"),
legend.name = "My_TA",
col = c("red", "blue")
)
# define my layout
layout(matrix(c(1, 2, 3), 3, 1),
heights = c(2.5, 1, 1.5)
)
# create the chart
chartSeries(dataset,
type = "candlesticks",
main = "",
show.grid = FALSE,
name = "My_Indicator_Name",
layout = NULL, # bypass internal layout
up.col = "blue",
dn.col = "red",
TA = c(newMyTA(),
addVo()
),
plot = TRUE,
theme = chartTheme("wsj")
)
我尝试过使用 legend 命令和选项 legend.name(对输出的控制非常有限)。我查看了 chartSeries 返回的 chob 对象,但我不知道下一步该做什么......
下图:
最佳答案
在学习了一些关于 R 内部结构、S3 和 S4 对象以及 quantmod 包的一些时间后,我想出了解决方案。它可用于更改图中的任何内容。
A) 如果图例属于二级指标窗口:
以我为例:
#get the chob object
my.chob <- chartSeries(dataset,
type = "candlesticks",
main = "",
show.grid = FALSE,
name = "My_Indicator_Name",
layout = NULL, # bypass internal layout
up.col = "blue",
dn.col = "red",
TA = c(newMyTA(),
addVo()
),
plot = FALSE, # do not plot, just get the chob
#plot = TRUE,
theme = chartTheme("wsj")
)
#if the legend is in a secundary window, and represents
#an indicator created with newTA(), this will work:
my.chob@passed.args$TA[[1]]@params$legend <- NULL
my.chob@passed.args$TA[[1]]@params$legend.name <- NULL
quantmod:::chartSeries.chob(my.chob)
B) 在任何其他情况下,可以修改“chartSeries.chob”、“chartTA”、“chartBBands”等,然后调用 chartSeries.chob
以我为例:
fixInNamespace("chartSeries.chob", ns = "quantmod")
quantmod:::chartSeries.chob(my.chob)
在legend()相关行的开头加上“#”即可。
就是这样。
关于R quantmod chartSeries newTA chob - 修改图例和轴(主要和次要),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23090963/
我正在使用 quantmod 包中的 chartSeries 函数,我使用的主题是 white.mono。图表非常干净,但我想删除与 y 轴相交的水平灰线。 有人知道怎么关掉这些吗?另外,是否可以关闭
我希望这不是多余的,因为我已经在谷歌上进行了广泛的搜索,但仍然没有找到答案。我正在绘制日内数据并希望在特定时间点放置一条垂直线。似乎我必须使用函数 addTA 但它总是在我的图表下方绘制一些奇怪的空白
我读过很多 R 文档,但我找不到任何我认为可以作为答案的内容。我的额头因撞到 table 而疼痛。 ;) 这是特定于library(quantmod)的,因为这就是我想要学习的内容,但我认为这也是一个
我是 R 的新手,使用您的网站非常有帮助。 不幸的是,我已经为我的代码苦苦挣扎了两天,所以我想要 问几个问题。我一直在尝试创建漂亮的图表以放入 pdf 表,但我对我使用过的所有包裹都没有什么问题 使用
我是 Shiny 的新手,在这里完成了 Shiny 教程: http://shiny.rstudio.com/tutorial/ 在第 6 课中,本教程向我们展示了如何创建一个应用程序,您可以在其中输
是否可以更改 Quantmod 中显示的图上的图例,以便显示值而不是变量名称?例如: library("quantmod") getSymbols("YHOO") temp1 <- 6 temp2 <
我想制作一个像这样的情节 https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110826/19da3834/attachment.p
这是一个高级问题。 我为 chartSeries quantmod 函数使用我自己的布局,我什至可以创建我自己的 newTA。一切正常。但是…… 我想做却做不到的事: a) 处理 3 个图表中每个图表
使用图表系列时,默认情况下它还会在图的左上角显示最后一个值。有什么办法可以阻止它这样做吗? 使用 addTA 添加新 TA 时,您可以通过设置参数 legend = ""来避免绘图上的最后一个值,但前
我正在使用图表系列,Y 轴被切断。我希望右侧的价格能够保留到小数点后两位。这似乎是边距或字体大小的问题,但经过一番搜索后,我找不到任何地方可以调整这些选项。我说边距是因为图表左侧似乎有足够的空间。 有
Jeff Ryan 的 quantmod 包是对 R 金融世界的杰出贡献。 我喜欢使用 chartSeries() 函数,但是当我试图让它同时显示多个 Pane 时,它不起作用。 par(mfrow=
我一直在为我的项目寻找一个好看的图表可视化解决方案,我终于找到了它 ( https://modernuicharts.codeplex.com )。我也把这个问题发到论坛上了,但是没有人回复... 我
我是一名优秀的程序员,十分优秀!