Placing x-axis labels between period ticks

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

For example, by default, R creates a graph that looks like this: (Note, I added axis(1,c(2001,2002,2003,2004,2005,2006,2007,2008,2009,2010)) to indicate a greater number of years labels, otherwise R uses only 2002 2004 2006 2008 2010 as labels). enter image description here

But I want to move the labels so that the plot looks like this: enter image description here

I tried to look, but I don’t even know what it is called.

+7
source share
1 answer

You can offset marks and ticks with separate calls on axis .

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

Plan everything, but don't lower the axles.

 plot(1:10, axes = FALSE) 

Mark the marks at half distance and turn off the ticks. (The return numbers are simply "interesting").

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

Add check marks back to normal position and do not reset marks. Add a field to complete the task.

Be careful, however, these labels now seem ambiguous, from the point of view of which they refer, and what is the position in reality (although everything begins to finish within a year, which should not be a problem).

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

offset labels from ticks

You can use axis(2, ...) to plot the y axis in the same way, or simply use the default values ​​with axis(2) .

+14
source

All Articles