如何设置用什么 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屋!