Search code examples
rdatetimeplotaxis-labels

Increase the length of plot tick marks


How can I increase the length of plot tick marks? Here is a small example:

r <- as.POSIXct(round(range(time), "mins"))
plot(time, x, t="l", xaxt = "n")
axis.POSIXct(1, at = seq(r[1], r[2], by = "min"), format = "%H:%M:%S")

which gives

enter image description here

As you can see, all the ticks are the same size. Is there a way to automatically increase the length of those ticks that are signed?


Solution

  • When creating a very specific axis layout, you typically need to add the axis after drawing the plot. Since you didn't have a reproducible example, I've created my own data set.

    1. Create a plot, but don't display the axis

      plot(1:10, axes=FALSE, frame=TRUE)
      
    2. Add in the x-scale. In this example, values 1,2,3, ...., 10. The argument tck specifies the tick length:

      ##The tck value should be smaller here
      axis(1, 1:10, tck=-0.05)
      
    3. Now add in an additional scale for "in-between" values. I've set labels="", so we don't print any values:

      axis(1, seq(0.5, 9.5, 1), labels=rep("", 10), tck=-0.01)
      

    This gives:

    enter image description here