Reputation: 39
Does anybody know how to adjust the labels in a base plot to NOT be equidistant? I have tick marks at different distance from each other and want the labels to center between these. The axis
function's hadj
argument only takes one value.
Upvotes: 0
Views: 363
Reputation: 2543
Just so that this question has a spelled-out answer (albeit a slightly different one than suggested in the comments):
ticks <- c(0, 1, 3, 6, 10)
labels <- c("one", "two", "three", "four") # one fewer than ticks
label.positions <- ticks[-1] - diff(ticks) / 2
plot(1:10, 1:10, xlim=c(-1, 11), axes=FALSE, ann=FALSE)
axis(1, at=ticks, labels=FALSE)
axis(1, at=label.positions, labels=labels, tick=FALSE)
Upvotes: 2