shadowtext: Add text to a plot with a contrasting background.

View source: R/shadowtext.R

shadowtextR Documentation

Add text to a plot with a contrasting background.

Description

This is similar to the text function, but it also puts a background shadow (outline) behind the text to make it stand out from the background better.

Usage

shadowtext(x, y = NULL, labels, col = "white", bg = "black",
  theta = seq(pi/32, 2 * pi, length.out = 64), r = 0.1, 
  cex = 1, ...)

Arguments

x

x-coordinates for the text

y

y-coordinates for the text

labels

The text labels to plot

col

Color of the text

bg

Color of the background shadow

theta

Angles for plotting the background

r

Thickness of the shadow relative to plotting size

cex

Character expansion passed through to text and used in computing text size.

...

Additional arguments passed on to text

Details

When adding text to a plot it is possible that the color of the text may make it difficult to see relative to its background. If the text spans different backgrounds then it may not be possible to find a single color to give proper contrast.

This function creates a contrasting shadow for the text by first plotting several copies of the text at angles theta and distance r in the background color, then plotting the text on top.

This gives a shadowing or outlining effect to the text making it easier to read on any background.

Value

This function is run for its side effects, returns NULL.

Author(s)

Greg Snow, 538280@gmail.com, with improvements by Thomas Danhorn

See Also

text

Examples

 plot(1:10, 1:10, bg='aliceblue')
 rect(3,3,5,8, col='navy')
 text(5,6, 'Test 1', col='lightsteelblue')
 shadowtext(5,4, 'Test 2', col='lightsteelblue')

TeachingDemos documentation built on May 29, 2024, 5:59 a.m.