Here is the code generating a plot of an xts object:
require("quantmod")
getSymbols("SPY")
plot(Cl(SPY))
Which yields the following plot:

Can you remove the y-axis values (the prices) from a plot of an xts object?
Hint: passing yaxt='n'
doesn't work.
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.
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"
.
来源:https://stackoverflow.com/questions/6165239/remove-y-axis-label-from-plot-of-an-xts-object