首页 > 解决方案 > 如何删除 plot.xts 中的网格线

问题描述

我正在xts使用 绘制一个对象plot.xts(),但我找不到删除网格线的参数,比如grid = FALSE或其他东西。有没有其他方法可以摆脱那些灰线?这是plot.xts()from R文档的用法。

# S3 method for xts
plot(x, y = NULL, ..., subset = "",
  panels = NULL, multi.panel = FALSE, col = 1:8, up.col = "green",
  dn.col = "red", bg = "#FFFFFF", type = "l", lty = 1, lwd = 2, lend = 1,
  main = deparse(substitute(x)), observation.based = FALSE,
  ylim = NULL, yaxis.same = TRUE, yaxis.left = TRUE, yaxis.right = TRUE,
  major.ticks = "months", minor.ticks = NULL,
  grid.ticks.on = "months", grid.ticks.lwd = 1, grid.ticks.lty = 1,
  grid.col = "darkgray", labels.col = "#333333", format.labels = TRUE,
  grid2 = "#F5F5F5", legend.loc = NULL)

标签: rplotxts

解决方案


您对 plot 的调用已指定grid.col = "darkgray",因此您会得到深灰色的网格线。要关闭它们,只需将其更改为grid.col = NA. 这是一个基于帮助页面中给出的示例的简单示例?plot.xts

library(xts)
data(sample_matrix)
sample.xts <- as.xts(sample_matrix)

par(mfrow=c(1,2))
plot(sample.xts[,"Close"], main="")
plot(sample.xts[,"Close"], main="", grid.col = NA)

有和没有网格线


推荐阅读