在周期性滴答声之间放置x轴标签 [英] Placing the x-axis labels between period ticks

查看:110
本文介绍了在周期性滴答声之间放置x轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在标记之间放置x轴标签。例如,默认情况下R会产生一个如下所示的图:
(注意,我添加了 axis(1,c( 2001,2002,2003,2004,2005,2007,2008,2009,2010))给出更大的标签年数,否则R仅使用 2002 2004 2006 2008年2010年作为标签。)



但我想移动标签,使得情节如下所示:

我试过看,但我甚至不知道它是做什么的。

$ b $你可以通过单独调用 axis 来抵消标签和ticks。



(下面的例子看起来不像您的数据,但这个想法是相同的。)



绘制任何东西,但保持轴关闭。

  plot(1:10,axes = FALSE)

以半间距偏移绘制标签并关闭刻度。 (反转数字只是为了有趣)。

  axis(1,at =(1:10)+ 0.5,labels = 10:1,tick = FALSE)

在正常位置添加滴答,并关闭标签。添加一个框来完成这项工作。



请小心,标签现在有点模棱两可,它们指的是哪个刻度,以及刻度位置实际上是多少(尽管一年开始到结束这应该不成问题)。

  axis(1,at =(1:10),labels = FALSE,tick = TRUE)
box )



您可以使用 axis(2,...)来以相同的方式构建y轴,或者仅使用 axis(2)的默认值。

I would like to place the x-axis labels between the ticks.

For example, by default R produces a graph that looks like this: (Note, I added axis(1,c(2001,2002,2003,2004,2005,2006,2007,2008,2009,2010)) to give the larger amount of label years, otherwise R only uses 2002 2004 2006 2008 2010 as labels.)

But I want to move the labels such that the plot looks like this:

I tried looking, but I don't even know what it's called doing this.

解决方案

You can offset the labels and the ticks with separate calls to axis.

(The example below does not look much like your data, but the idea is the same.)

Plot whatever, but keep the axes off.

plot(1:10, axes = FALSE)

Plot the labels at a half spacing offset and turn off the ticks. (Reverse the numbers just to be "interesting").

axis(1, at = (1:10) + 0.5, labels = 10:1, tick = FALSE)

Add the ticks back at the normal position, and keep the labels off. Add a box to finish the job.

Be careful though, the labels are now kind of ambiguous in terms of which tick they refer to, and what the tick position actually is (though for a year start to end that should not be a problem).

axis(1, at = (1:10), labels = FALSE, tick = TRUE)
box()

You can use axis(2, ...) to construct the y-axis in the same way, or just use defaults with axis(2).

这篇关于在周期性滴答声之间放置x轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆