简体   繁体   English

如何设置使用plot()标记x轴的方式?

[英]How do I set what plot() labels the x-axis with?

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? 我有一个我想制作的plot(),但是我不想将x值用作轴标签...在标准中,我想要一个不同的字符向量用作标签方式:使用尽可能多的东西,丢弃其他东西,等等。我该如何传递给plot()来实现此目的?

For example, consider 例如,考虑

d <- data.frame(x=1:5,y=10:15,x.names=c('a','b','c','d','e'))

In barplot, I would pass barplot(height=d$y,names.arg=d$x.names) , but in this case the actual x-values are important. 在barplot中,我将传递barplot(height=d$y,names.arg=d$x.names) ,但是在这种情况下,实际的x值很重要。 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. 所以我想要一个类似plot(x=d$x,y=d$y,type='l',names.arg=d$x.names) ,但这不起作用。

I think you want to first suppress the labels on the x axis with the xaxt="n" option: 我认为您想首先使用xaxt =“ n”选项取消x轴上的标签:

plot(flow~factor(month),xlab="Month",ylab="Total Flow per Month",ylim=c(0,55000), xaxt="n")  

then use the axis command to add in your own labels. 然后使用axis命令添加您自己的标签。 This example assumes the labels are in an object called month.name 本示例假定标签位于名为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 . 我必须查找如何执行此操作,然后从这里窃取了示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM