如何设置使用plot()标记x轴的方式? [英] How do I set what plot() labels the x-axis with?
问题描述
我有一个我要绘制的plot(),但我不想将x值用作轴标签...我想要一个不同的字符向量,我想将其用作标签,以标准的方式:使用尽可能多的东西,丢弃其他东西,等等.我该如何传递给plot()来做到这一点?
I have a plot() that I'm trying to make, but I do not want the x-values to be used as the axis labels...I want a different character vector that I want to use as labels, in the standard way: Use as many as will fit, drop the others, etc. What should I pass to plot() to make this happen?
例如,考虑
d <- data.frame(x=1:5,y=10:15,x.names=c('a','b','c','d','e'))
在小节中,我会通过barplot(height=d$y,names.arg=d$x.names)
,但是在这种情况下,实际的x值很重要.所以我想要一个类似plot(x=d$x,y=d$y,type='l',names.arg=d$x.names)
的类似物,但这不起作用.
In barplot, I would pass barplot(height=d$y,names.arg=d$x.names)
, but in this case the actual x-values are important. So I would like an analog such as plot(x=d$x,y=d$y,type='l',names.arg=d$x.names)
, but that does not work.
推荐答案
我想您首先要使用xaxt ="n"选项取消x轴上的标签:
I think you want to first suppress the labels on the x axis with the xaxt="n" option:
plot(flow~factor(month),xlab="Month",ylab="Total Flow per Month",ylim=c(0,55000), xaxt="n")
然后使用axis命令添加您自己的标签.此示例假定标签位于名为month.name
then use the axis command to add in your own labels. This example assumes the labels are in an object called month.name
axis(1, at=1:12, labels=month.name)
I had to look up how to do this and I stole the example from here.
这篇关于如何设置使用plot()标记x轴的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!