Remove y-axis label from plot of an xts object

时光毁灭记忆、已成空白 提交于 2019-12-01 20:44:02

Removing the y-axis is easy, but it also removes the x-axis. A couple options:

1) Easy -- use plot.zoo:

plot.zoo(Cl(SPY), yaxt="n", ylab="")

2) Harder-ish -- take pieces from plot.xts:

plot(Cl(SPY), axes=FALSE)
axis(1, at=xy.coords(.index(SPY), SPY[, 1])$x[axTicksByTime(SPY)],
  label=names(axTicksByTime(SPY)), mgp = c(3, 2, 0))

3) Customize-ish -- modify plot.xts so axes= accepts a vector of axes to plot and/or TRUE/FALSE.

Adding to Joshua's answer, to modify plot.xts(), all you need to do is alter the following section:

    if (axes) {
      if (minor.ticks) 
        axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB")
      axis(1, at = xycoords$x[ep], labels = names(ep), las = 1,lwd = 1, mgp = c(3, 2, 0))
    #This is the line to change:
    if (plotYaxis) axis(2)
    }

and obviously you add the parameter plotYaxis=TRUE to the function definition.

AndyC

You can also try specifying that the x and y as labels are empty, or contain no values/characters. Try using the term xlab="" in your plot command: e.g. plot(beers,ranking,xlab="",ylab="")

By not including anything between the quotation marks, R doesn't plot anything. Using this command, you can also specific the labels, so to make the label for the x axis 'beer', use the term xlab="beer".

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!