[英]Remove y-axis label from plot of an xts object
Here is the code generating a plot of an xts object:这是生成 xts object 的 plot 的代码:
require("quantmod")
getSymbols("SPY")
plot(Cl(SPY))
Which yields the following plot:产生以下 plot:
Can you remove the y-axis values (the prices) from a plot of an xts object?您可以从 xts object 的 plot 中删除 y 轴值(价格)吗?
Hint : passing yaxt='n'
doesn't work .提示:传递
yaxt='n'
不起作用。
Removing the y-axis is easy, but it also removes the x-axis.移除 y 轴很容易,但也会移除 x 轴。 A couple options:
几个选项:
1) Easy -- use plot.zoo
: 1)简单——使用
plot.zoo
:
plot.zoo(Cl(SPY), yaxt="n", ylab="")
2) Harder-ish -- take pieces from plot.xts
: 2) Harder-ish - 从
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
. 3)自定义-ish - 修改
plot.xts
所以axes=
接受到 plot 和/或TRUE
/ FALSE
的轴向量。
Adding to Joshua's answer, to modify plot.xts(), all you need to do is alter the following section:添加到 Joshua 的答案中,要修改 plot.xts(),您需要做的就是更改以下部分:
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.显然您将参数 plotYaxis=TRUE 添加到 function 定义中。
You can also try specifying that the x and y as labels are empty, or contain no values/characters.您还可以尝试将 x 和 y 作为标签指定为空,或不包含值/字符。 Try using the term
xlab=""
in your plot command: eg plot(beers,ranking,xlab="",ylab="")
尝试在 plot 命令中使用术语
xlab=""
:例如plot(beers,ranking,xlab="",ylab="")
By not including anything between the quotation marks, R doesn't plot anything.通过不包括引号之间的任何内容, R 不会 plot 任何内容。 Using this command, you can also specific the labels, so to make the label for the x axis 'beer', use the term
xlab="beer"
.使用此命令,您还可以指定标签,因此要为 x 轴“啤酒”制作 label,请使用术语
xlab="beer"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.