Horizontal alignment of "large" labels is shifted when using the adj argument in the text

The textargument adjallows you to customize labelswith respect to xand y. For example, values adj(0, 1) mean left-right alignment, i.e. The upper left corner of the label is placed in a predetermined coordinate x, y.

This works great with the default character extension cex = 1. But when I need a larger label created by increasing cex, the position of the label is shifted horizontally from the given coordinate and adj.

Here is a small example demonstrating this:

# a basic plot
plot(1:10, asp = 1, cex = 1)

# a red reference mark at 5, 5
points(x = 5, y = 5, pch = 3, cex = 3, col = 'red')

# a label of default size (cex = 1), left top adjusted
text(x = 5, y = 5, labels = 'H', cex = 1, adj = c(0, 1))

# a large label (cex = 8) with same position and adjustment as above becomes offset horizontally
text(x = 5, y = 5, labels = 'H', cex = 8, adj = c(0, 1), col = rgb(0.1, 0.9, 0.1, 0.5))

enter image description here

Horizontal shift occurs for all left / right / top / top alignment combinations:

plot(1:10, cex = 1)
points(x = 5, y = 5, pch = 3, lwd = 4, cex = 4, col = 'red')

text(x = 5, y = 5, labels = "H", cex = 1, adj = c(0, 0))
text(x = 5, y = 5, labels = "H", cex = 1, adj = c(0, 1))
text(x = 5, y = 5, labels = "H", cex = 1, adj = c(1, 0))
text(x = 5, y = 5, labels = "H", cex = 1, adj = c(1, 1))

text(x = 5, y = 5, labels = "H", cex = 8, adj = c(0, 0), col = "green")
text(x = 5, y = 5, labels = "H", cex = 8, adj = c(0, 1), col = "green")
text(x = 5, y = 5, labels = "H", cex = 8, adj = c(1, 0), col = "green")
text(x = 5, y = 5, labels = "H", cex = 8, adj = c(1, 1), col = "green")

enter image description here

, cex > 1?

+5
1

. , . R R :

" R- , ".

( , ) . , . . , ( 'glyph metrics') .

enter image description here

, , cex = 1. "" ( cex), , .

, , :
" ."

Q & A . .

+2

All Articles