Placing the x-axis labels between period ticks
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)
.
精彩评论