R 中带轮廓的文本标签
Text labels with outline in R
我想知道是否可以在 R 中绘制带有轮廓的文本,这样文本就可以独立于背景阅读(就像模因上的文本)。以下(显然)失败了:
# prepare a colorful background
randcolors <- sprintf( "#%02X%02X%02X99", sample(1:255, 1000, replace=T), sample(1:255, 1000,replace=T), sample(1:255, 1000, replace=T))
plot( NULL, xlim=c(0,1), ylim=c(0,1), xaxt="n", bty="n", yaxt="n")
points( runif(1000, 0, 1 ), runif( 1000, 0, 1 ), cex=runif(1000, 0.5, 5), col= randcolors, pch= 19)
text( 0.5, 0.5, "test text", cex= 5 )
text( 0.5, 0.5, "test text", cex= 4.5, col="white" )
结果并不壮观:
显然,我可以先创建一个白色或半透明的背景,但实际上我更希望有漂亮的轮廓。
尝试 TeachingDemos
包中的 shadowtext
:
shadowtext( 0.5, 0.5, "test text", cex= 4.5, col="white" , r=0.3)
我想知道是否可以在 R 中绘制带有轮廓的文本,这样文本就可以独立于背景阅读(就像模因上的文本)。以下(显然)失败了:
# prepare a colorful background
randcolors <- sprintf( "#%02X%02X%02X99", sample(1:255, 1000, replace=T), sample(1:255, 1000,replace=T), sample(1:255, 1000, replace=T))
plot( NULL, xlim=c(0,1), ylim=c(0,1), xaxt="n", bty="n", yaxt="n")
points( runif(1000, 0, 1 ), runif( 1000, 0, 1 ), cex=runif(1000, 0.5, 5), col= randcolors, pch= 19)
text( 0.5, 0.5, "test text", cex= 5 )
text( 0.5, 0.5, "test text", cex= 4.5, col="white" )
结果并不壮观:
显然,我可以先创建一个白色或半透明的背景,但实际上我更希望有漂亮的轮廓。
尝试 TeachingDemos
包中的 shadowtext
:
shadowtext( 0.5, 0.5, "test text", cex= 4.5, col="white" , r=0.3)