您想删除右手轴。 plot.xts(..., yaxis.right = TRUE, ...) 中有一个参数。所以
library('xts')
#> Loading required package: zoo
#>
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#>
#> as.Date, as.Date.numeric
data(sample_matrix)
sample.xts <- as.xts(sample_matrix, descr='my new xts object')
plot(sample.xts, yaxis.right = FALSE)
做你想做的。
我尝试解决第二个问题,删除了右上角的标签。检查plot.xts() 的源代码发现标签被硬编码到主标题中。即使设置 main = '' 也不会删除它。您可以通过编辑 plot.xts() 并将其复制到新函数来解决此问题。
plotxts <- fix("plot.xts")
# In the editor that opens, replace the lines below:
### text.exp <- c(expression(text(xlim[1], 0.5, main, font = 2,
### col = theme$labels, offset = 0, cex = 1.1, pos = 4)),
### expression(text(xlim[2], 0.5, paste(start(xdata[xsubset]),
### end(xdata[xsubset]), sep = " / "), col = theme$labels,
### adj = c(0, 0), pos = 2)))
### cs$add(text.exp, env = cs$Env, expr = TRUE)
# with these lines:
### text.exp <- expression(text(xlim[1], 0.5, main, font = 2,
### col = theme$labels, offset = 0, cex = 1.1, pos = 4))
# Finally, you need to ensure your copy's environment is the xts namespace:
environment(plotxts) <- asNamespace("xts")
plotxts(sample.xts, yaxis.right = FALSE, main = "Main Title")
第二个,也许是
更简单的选择是使用不同的绘图功能并对其进行修改以生成您想要的网格线等。我会开始
plot.zoo() 因为它已经很好地处理了时间序列。
zoo::plot.zoo(sample.xts, screens = 1, xlab="", las=2, main="Main Title")
grid() # add the grid
至少让网格在那里。如果没有正确频率的数据,我无法测试它是否会以相同的方式处理 x 轴标签。