Remove the Y axis label from the xts object graph

Here is the code generating the graph of the xts object:

require("quantmod")
getSymbols("SPY")
plot(Cl(SPY))

Which gives the following graph:

graph

Can you remove the y-axis (price) values ​​from the xts chart?

Hint: the transmission yaxt='n'does not work.

+3
source share
3 answers

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

1) Ease of use plot.zoo:

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

2) Heavier - 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, therefore it axes=accepts a vector of axes for construction and / or TRUE/ FALSE.

+4
source

Adding an answer to Joshua to change plot.xts (), all you have to do is change 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)
    }

, , plotYaxis = TRUE .

+1

You can also try to indicate that the x and y labels are empty or do not contain values ​​/ characters. Try using the term xlab=""in your team: for exampleplot(beers,ranking,xlab="",ylab="")

Without including anything between quotation marks, R draws nothing. Using this command, you can also specify labels to make a label for the x axis "beer", use the term xlab="beer".

0
source

All Articles