【发布时间】:2019-06-27 18:53:33
【问题描述】:
我希望使用 R 中 xts 对象的内置包 plot.xts() 绘制多个时间序列。
目前,我正在使用以下内容:
## Create xts dataset
ust <- merge.xts(us.3m,
us.6m,
us.2y,
us.3y,
us.5y,
us.10y,
us.30y)
## Create color scheme using rainbow()
tsRainbow = rainbow(ncol(as.zoo(ust)))
## Create plot of dataset
plot.xts(ust, screens=1,
major.ticks="years",
main="U.S. Bond Yield Evolution",
yaxis.right=FALSE,
grid.ticks.on="years",
col=tsRainbow)
## Add legend
addLegend("topright",
legend.names=c("US 3M", "US 6M",
"US 2Y", "US 3Y",
"US 5Y", "US 10Y", "US 30Y"),
col=tsRainbow,
lty=c(1,1,1,1,1,1,1),
lwd=c(2,2,2,2,2,2,2),
ncol=2,
bg="white")
这会产生以下图表:
我想给图例添加一个白色的叠加背景,这样在图例区域就看不到网格线了。这将使图表区域更加干净,并允许在类似出版物的文档中看到图例标签。
编辑
@JuliusVainora 给出的解决方案效果很好。简单解决我的问题。
【问题讨论】: