KPJ
KPJ

Reputation: 39

Non-equidistant axis labels

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

Answers (1)

drammock
drammock

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)

screenshot of plot with unequally spaced axis ticks and axis labels centered between ticks

Upvotes: 2

Related Questions