Package 'pBrackets'

Title: Plot Brackets
Description: Adds different kinds of brackets to a plot, including braces, chevrons, parentheses or square brackets.
Authors: Andreas Schulz
Maintainer: Andreas Schulz <[email protected]>
License: GPL (>= 3.0)
Version: 1.0.1
Built: 2024-12-18 06:46:04 UTC
Source: CRAN

Help Index


Plot Brackets

Description

Adds different kinds of brackets to a plot, including braces, chevrons, parentheses or square brackets.

Details

Package: pBrackets
Type: Package
Version: 1.1
Date: 2021-05-17
License: GPL version 2 or newer

Author(s)

Andreas Schulz Maintainer: Andreas Schulz <[email protected]>


Add brackets to a plot.

Description

Draw different kinds of brackets between pairs of points.

Usage

brackets(x1, y1, x2, y2, h = NULL,  ticks = 0.5, curvature = 0.5, type = 1,
col = 1, lwd = 1, lty = 1, xpd = FALSE)

Arguments

x1, y1

coordinates of points from which to draw.

x2, y2

coordinates of points to which to draw.

h

brackets height (with ticks), given in euclidean distance. For horizontal brackets it is the height in y-units, for vertical brackets it is the width in x-units. Generally it is the euclidean distance: sqrt(x^2+y^2).

ticks

A single value or a vector of values in (0, 1), gives the relative position of the ticks on the bracket. Use NA or NULL to make a bracket without ticks. Negative values resulting in ticks inside of brackets. Values 0 or 1, flip the starting or end edges of the brackets.

curvature

A value in [0, 1], gives the amount of space on the bracket that is used for the curve, it is getting automatically smaller if many ticks are specified or the tick is near the edge.

type

A value in: 1 to 5 for different brackets forms, see example.

  • 1: braces

  • 2: braces 2

  • 3: stump brackets

  • 4: square brackets

  • 5: parentheses

col

color code or name of color.

lwd

line width

lty

line type

xpd

A logical value. If FALSE, all plotting is clipped to the plot region, if TRUE, all plotting is clipped to the figure region.

Examples

par(mar=c(1,1,1,1))
plot(0,0, type='n', xlim=c(0,20), ylim=c(0,20), axes=FALSE, xlab='', ylab='')
abline(h=seq(0,20), v=seq(0, 7), col=rgb(0.8, 0.9, 0.95))

brackets(0, 18, 7, 20, lwd=2)
text(8, 20, labels=expression(paste(bold('Braces:'), ' default')), adj=c(0,0))

brackets(0, 16, 7, 18, lwd=2, curvatur=1, type=2)
text(8, 18, labels=expression(paste(bold('Braces 2:'), ' curvatur=1, type=2')), adj=c(0,0))

brackets(0, 14, 7, 16, lwd=2, ticks=NA, curvatur=1, type=5)
text(8, 16, labels=expression(paste(bold('Parentheses:'), ' ticks=NA, curvature=1, type=5')),
 adj=c(0,0))

brackets(0, 12, 7, 14, lwd=2, ticks=NA, type=4, h=0.5)
text(8, 14, labels=expression(paste(bold('Square brackets:'), ' ticks=NA, type=4')), adj=c(0,0))

brackets(0, 10, 7, 12, lwd=2, ticks=NA, curvature=1, type=3)
text(8, 12, labels=expression(paste(bold('Chevrons:'), ' ticks=NA, curvature=1, type=3')),
 adj=c(0,0))

brackets(0, 8, 7, 10, lwd=2, ticks=NA, type=3, curvature=0.2, h=0.75)
text(8, 10, labels=expression(paste(bold('Stump brackets:'), ' ticks=NA, curvature=0.2, type=3')),
adj=c(0,0))

brackets(0, 6, 7, 8, lwd=2, type=4)
text(8, 8, labels=expression(paste(bold('Square brackets with tick:'), ' type=4')), adj=c(0,0))

brackets(0, 4, 7, 6, lwd=2, ticks=c(0.25, 0.75))
text(8, 6, labels=expression(paste(bold('Double tick braces:'), ' ticks=c(0.25, 0.75)')),
adj=c(0,0))

brackets(0, 2, 7, 4, lwd=2, ticks=-0.5, h=0.5)
text(8, 4, labels=expression(paste(bold('Negative tick braces:'), ' ticks=-0.5')), adj=c(0,0))

brackets(0, 0, 7, 2, lwd=2, ticks=c(-0.2, -0.4, -0.6, -0.8, 1), type=4)
text(8,2,labels=expression(paste(bold('Multiples ticks:'),'ticks=c(-0.2,-0.4,-0.6,-0.8,1),type=4')),
adj=c(0,0))

Add brackets to a grid pannel.

Description

Draw brackets between pairs of points. (grid)

Usage

grid.brackets(x1, y1, x2, y2, h = NULL, ticks = 0.5, curvature = 0.5,
type = 1, col = 1, lwd = 1, lty = "solid")

Arguments

x1, y1

coordinates of points from which to draw.

x2, y2

coordinates of points to which to draw.

h

brackets height (with ticks), given in npc units.

ticks

A single value or a vector of values in (0, 1), gives the relative position of the ticks on the bracket. Use NA or NULL to make a bracket without ticks. Negative values resulting in ticks inside of brackets. Values 0 or 1, flip the starting or end edges of the brackets.

curvature

A value in [0, 1], gives the amount of space on the bracket that is used for the curve, it is getting automatically smaller if many ticks are specified or the tick is near the edge.

type

A value in: 1 to 5 for different brackets forms, see example.

  • 1: braces

  • 2: braces 2

  • 3: stump brackets

  • 4: square brackets

  • 5: parentheses

col

color code or name of color.

lwd

line width

lty

line type

Note

To plot brackets outside of ploting region use trellis.focus("panel", 1, 1, clip.off=TRUE)

Examples

library(grid)
grid.newpage()
pushViewport(plotViewport(margins=c(0.5, 0.5, 0.5, 0.5), xscale = c(-1, 21), yscale = c(-1, 21)))
grid.grill(h=unit(seq(0,20),'native'), v=unit(seq(0,7),'native'), gp=gpar(col=rgb(0.8, 0.9, 0.95)))

grid.brackets(0, 18, 7, 20, lwd=2)
grid.text(x=unit(8, 'native'), y=unit(20, 'native'), label=expression(paste(bold('Braces:'),
' default')), hjust = 0, vjust=0)

grid.brackets(0, 16, 7, 18, lwd=2, curvatur=1, type=2)
grid.text(x=unit(8, 'native'), y=unit(18, 'native'), label=expression(paste(bold('Braces 2:'),
' curvatur=1, type=2')), hjust = 0, vjust=0)

grid.brackets(0, 14, 7, 16, lwd=2, ticks=NA, curvatur=1, type=5)
grid.text(x=unit(8, 'native'), y=unit(16, 'native'), label=expression(paste(bold('Parentheses:'),
' ticks=NA, curvature=1, type=5')), hjust = 0, vjust=0)

grid.brackets(0, 12, 7, 14, lwd=2, ticks=NA, type=4, h=0.03)
grid.text(x=unit(8,'native'), y=unit(14,'native'), label=expression(paste(bold('Square brackets:'),
' ticks=NA, type=4')), hjust = 0, vjust=0)

grid.brackets(0, 10, 7, 12, lwd=2, ticks=NA, curvature=1, type=3)
grid.text(x=unit(8, 'native'), y=unit(12, 'native'), label=expression(paste(bold('Chevrons:'),
' ticks=NA, curvature=1, type=3')), hjust = 0, vjust=0)

grid.brackets(0, 8, 7, 10, lwd=2, ticks=NA, type=3, curvature=0.2, h=0.04)
grid.text(x=unit(8, 'native'), y=unit(10, 'native'), label=expression(paste(bold('Stump brackets:'),
' ticks=NA, curvature=0.2, type=3')), hjust = 0, vjust=0)

grid.brackets(0, 6, 7, 8, lwd=2, type=4)
grid.text(x=unit(8,'native'), y=unit(8,'native'),
label=expression(paste(bold('Square brackets with tick:'), ' type=4')), hjust = 0, vjust=0)

grid.brackets(0, 4, 7, 6, lwd=2, ticks=c(0.25, 0.75))
grid.text(x=unit(8,'native'), y=unit(6,'native'),
label=expression(paste(bold('Double tick braces:'), ' ticks=c(0.25, 0.75)')), hjust = 0, vjust=0)

grid.brackets(0, 2, 7, 4, lwd=2, ticks=-0.5, h=0.03)
grid.text(x=unit(8, 'native'), y=unit(4, 'native'),
label=expression(paste(bold('Negative tick braces:'), ' ticks=-0.5')), hjust = 0, vjust=0)

grid.brackets(0, 0, 7, 2, lwd=2, ticks=c(-0.2, -0.4, -0.6, -0.8, 1), type=4)
grid.text(x=unit(8,'native'), y=unit(2,'native'), label=expression(paste(bold('Multiples ticks:'),
' ticks=c(-0.2,-0.4,-0.6,-0.8, 1), type=4')), hjust = 0, vjust=0)

popViewport()