r - 在 xts 循环图中更改名称
问题描述
我在四个 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 帖子中删除了每个图顶部的样本空间: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"
)))
这是我到目前为止的情节。都称为篮子 [ ,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]))
}
推荐阅读
- postgresql - Typeorm 不想更新数据库
- excel - 为什么 find 函数出现错误(通过其他列表)
- javascript - 为什么这在 for 循环中有效,但在 forEach 中无效?(数组不是构造函数错误)
- haskell - Haskell 可以建模模型吗?
- graphics - 如何在 RStudio 中制作生产质量的频率表?
- java - GetId() 在两个不同的 Id 上
- assembly - 使用通用 CPU 图在执行汇编指令时模拟数据移动
- angular - 仪表板上所有小部件的通用加载器,使用 Angular 加载器服务
- python - Python从下载链接获取s3文件
- xml - 带有条件的 XSLT sum() - 返回“不允许将多个项目的序列作为第一个参数”