Я хочу нанести метку на линию в монохромном изображении. Поэтому мне нужна маленькая белая рамка на каждой букве этикетки.
Граница или фон прямоугольника текстовой метки бесполезны, поскольку скрывают много данных, нанесенных на график.
Есть ли способ поместить границы, тени или буфера вокруг текстовых меток на графиках R?
РЕДАКТИРОВАТЬ:
shadowtext <- function(x, y=NULL, labels, col='white', bg='black',
theta= seq(pi/4, 2*pi, length.out=8), r=0.1, ... ) {
xy <- xy.coords(x,y)
xo <- r*strwidth('x')
yo <- r*strheight('x')
for (i in theta) {
text( xy$x + cos(i)*xo, xy$y + sin(i)*yo, labels, col=bg, ... )
}
text(xy$x, xy$y, labels, col=col, ... )
}
pdf(file="test.pdf", width=2, height=2); par(mar=c(0,0,0,0)+.1)
plot(c(0,1), c(0,1), type="l", lwd=20, axes=FALSE, xlab="", ylab="")
text(1/6, 1/6, "Test 1")
text(2/6, 2/6, "Test 2", col="white")
shadowtext(3/6, 3/6, "Test 3")
shadowtext(4/6, 4/6, "Test 4", col="black", bg="white")
shadowtext(5/6, 5/6, "Test 5", col="black", bg="white", theta = seq(pi/4, 2*pi, length.out=24))
dev.off()
Приведенный выше код использует решение от koekenbakker. Это хорошо для графики PNG, но мне нужен другой подход для PDF с высоким разрешением.