Text labels with outline in R

I wonder if it is possible to draw text with an outline in R so that the text is read regardless of the background (for example, text in memes). The following (obviously) failure:

# 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" ) 

The result is not impressive:

enter image description here

It’s clear that I can first create a white or translucent background, but in fact I would prefer to have nice outlines.

+5
source share
1 answer

Try shadowtext from TeachingDemos package:

  shadowtext( 0.5, 0.5, "test text", cex= 4.5, col="white" , r=0.3) 

shadow text

+7
source

Source: https://habr.com/ru/post/1216293/


All Articles