highlight: Highlight areas on a plot

View source: R/highlight.R

highlightR Documentation

Highlight areas on a plot

Description

Draws a series of highlights (translucent rectangles) onto a base R plot.

Usage

highlight(
  x = NULL,
  y = NULL,
  col = "#ffff00",
  label = NA,
  alpha = 0.2,
  shrink = TRUE,
  border = NA,
  ...
)

Arguments

x

x coordinates for highlight areas.

y

y coordinates for highlight areas (usually leave NULL).

col

fill colours for rectangles.

label

text labels for each rectangle.

alpha

opacity level (0 to 1) for rectangles.

shrink

if TRUE or numeric and y is NULL, lowers the top of each subsequent rectangle by the specified number of user plotting units so that the labels don't overlap; TRUE uses the line height times 2, which is a decent default. Set to zero for no shrinking.

border

colour for rectangle borders; NA (default) to omit.

...

other arguments to pass on to rect().

Details

x and y can either be: NULL, in which case the extent of the plotted area is used; a numeric vector, interleaved such that the elements are interpreted as e.g. c(x1_start, x1_end, x2_start, x2_end, ...); a list with two elements, e.g. list(c(x1_start, x2_start, ...), c(x1_end, x2_end, ...)); or a matrix with two columns (first column "starts", second column "ends").

Arguments are recycled as needed.

Examples

## Not run: 
curve(dnorm(x), 0, 4)
highlight(x = c(0, 0, 1, 3, 2, 4), label = letters[1:3], col = c("red", "blue", "purple"))

## End(Not run)

nicholasdavies/shmanipulate documentation built on July 16, 2025, 5:39 p.m.