在 xts 循环图中更改名称
Change name in xts loop plots
我在四个 xts 图上有一个循环:
basket <- cbind(AAPLG, GEG, SPYG, WMTG)
tickers <- c("AAPL", "GE", "SPY", "WMT")
par(mar = c(3, 3, 3, 3))
par(mfrow=c(2,2))
for (i in 1:4){
print(plot.xts(x = basket[, i], xlab = "Time", ylab = "Cumulative Return",
, major.ticks= "years",
minor.ticks = FALSE, col = "black"))
}
我已经从 SO post 中删除了每个图顶部的示例 space:Changes in plotting an XTS object
但是,有没有办法将每个图的标题更改为上面的股票代码?所以当 运行 时,循环 basket[, i]
将被 tickers <- c("AAPL", "GE", "SPY", "WMT")
数据样本:
structure(c(1, 1.01463414634146, 0.926829268292683, 0.970731707317073,
0.953658536585366, 1, 0.998263888888889, 1.01159722222222, 1.05076388888889,
1.05034722222222, 1, 1.00178890876565, 0.985688729874776, 1.04293381037567,
1.04651162790698, 1, 0.976675478152698, 0.990359197636448, 1.06515316436013,
1.04571606282071), class = c("xts", "zoo"), index = structure(c(946944000,
947030400, 947116800, 947203200, 947462400), tzone = "UTC", tclass = "Date"), .Dim = 5:4, .Dimnames = list(
NULL, c("new.close", "new.close.1", "new.close.2", "new.close.3"
)))
这是我目前的情节。全部称为 basket [ ,i] ,信息量不大。
另外:ylab 和 xlab 没有显示在图中,即使设置了高边距。有人知道解决方案吗?
在图中调用 main 的 ticker 对象函数
for (i in 1:4){
print(plot.xts(x = basket[, i], xlab = "Time", ylab = "Cumulative Return",
major.ticks= "years", minor.ticks = FALSE,
col = "black", main = tickers[i]))
}