| Type: | Package | 
| Title: | Curly Braces for 'ggplot2' | 
| Depends: | R (≥ 4.3) | 
| Imports: | ggplot2 (≥ 3.4.2), stats (≥ 4.3.1) | 
| Version: | 0.1.2 | 
| Description: | Provides curly braces and square brackets in 'ggplot2' plus matching text. stat_brace() plots braces/brackets to embrace data. stat_bracetext() plots corresponding text, fitting to the braces from stat_brace(). | 
| License: | MIT + file LICENSE | 
| Encoding: | UTF-8 | 
| RoxygenNote: | 7.3.2 | 
| URL: | https://github.com/NicolasH2/ggbrace | 
| Suggests: | knitr, rmarkdown | 
| NeedsCompilation: | no | 
| Packaged: | 2025-07-08 18:26:08 UTC; infoh | 
| Author: | Nicolas Huber [aut, cre, cph] | 
| Maintainer: | Nicolas Huber <info.huber@aol.de> | 
| Repository: | CRAN | 
| Date/Publication: | 2025-07-09 03:40:02 UTC | 
Imports: stats
Description
Imports: stats
Usage
.coordCorrection(
  x,
  y,
  rotate,
  mid,
  textdistance = NULL,
  distance,
  outerstart,
  width,
  outside,
  bending,
  discreteAxis = FALSE
)
Arguments
x | 
 vector, x values of all data points  | 
y | 
 vector, y value of all data points  | 
rotate | 
 number in degrees. Defines where the brace points to: 0=up (default), 90=right, 180=down, 270=left  | 
mid | 
 number from 0.25 to 0.75. Position of the pointer within the brace space. If NULL (default), will be determined by data.  | 
textdistance | 
 number. Distance of the label to the brace pointer  | 
distance | 
 number. Space between the brace and the nearest data point. If NULL (default), will be determined by data.  | 
outerstart | 
 number. If not NULL, overwrites distance and sets all braces to the same origin  | 
width | 
 number. Distance from the brace's start to its tip. If NULL (default), will be determined by data.  | 
outside | 
 boolean. If TRUE (default), brace is next to the data area. If FALSE, brace is inside the data area  | 
bending | 
 number from 0 to 0.5. Determines bend of the brace curves (0=rectangular). If NULL (default), will be determined by data. If too high, values will result in zick-zack lines  | 
discreteAxis | 
 boolean. Set to TRUE if the axis along which the brace expands is discrete (often true for bar graphs)  | 
Imports: stats
Description
Imports: stats
Usage
.seekBrace(x, y, rotate, bending, npoints, bracketType)
Arguments
x | 
 vector, x values of all data points  | 
y | 
 vector, y value of all data points  | 
rotate | 
 number in degrees. Defines where the brace points to: 0=up (default), 90=right, 180=down, 270=left  | 
bending | 
 number from 0 to 0.5. Determines bend of the brace curves (0=rectangular). If NULL (default), will be determined by data. If too high, values will result in zick-zack lines  | 
npoints | 
 integer. Number of points generated for the brace curves. Will be rounded to be a multiple of 4 for calculation purposes.  | 
bracketType | 
 text choice. Either "curly" (default) or "square"  | 
create curly braces as a layer in ggplot
Description
Imports: ggplot2
Usage
stat_brace(
  mapping = NULL,
  data = NULL,
  ...,
  rotate = 0,
  width = NULL,
  mid = NULL,
  outside = TRUE,
  distance = NULL,
  outerstart = NULL,
  bending = NULL,
  show.legend = FALSE,
  inherit.aes = TRUE,
  discreteAxis = FALSE,
  bracketType = "curly",
  npoints = 100
)
Arguments
mapping | 
 Set of aesthetic mappings created by   | 
data | 
 The data to be displayed in this layer. There are three options: If  A  A   | 
... | 
 Other arguments passed on to  
  | 
rotate | 
 number in degrees. Defines where the brace points to: 0=up (default), 90=right, 180=down, 270=left  | 
width | 
 number. Distance from the brace's start to its tip. If NULL (default), will be determined by data.  | 
mid | 
 number from 0.25 to 0.75. Position of the pointer within the brace space. If NULL (default), will be determined by data.  | 
outside | 
 boolean. If TRUE (default), brace is next to the data area. If FALSE, brace is inside the data area  | 
distance | 
 number. Space between the brace and the nearest data point. If NULL (default), will be determined by data.  | 
outerstart | 
 number. If not NULL, overwrites distance and sets all braces to the same origin  | 
bending | 
 number from 0 to 0.5. Determines bend of the brace curves (0=rectangular). If NULL (default), will be determined by data. If too high, values will result in zick-zack lines  | 
show.legend | 
 logical. Should this layer be included in the legends?
  | 
inherit.aes | 
 If   | 
discreteAxis | 
 boolean. Set to TRUE if the axis along which the brace expands is discrete (often true for bar graphs)  | 
bracketType | 
 text choice. Either "curly" (default) or "square"  | 
npoints | 
 integer. Number of points generated for the brace curves. Will be rounded to be a multiple of 4 for calculation purposes.  | 
Value
ggplot2 layer object (geom_path) that can directly be added to a ggplot2 object.
Examples
library(ggbrace)
library(ggplot2)
data(iris)
# regular braces
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace()
 # rotated braces
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace(rotate = 90)
 # braces inside the given coordinates
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace(outside = FALSE)
 # braces with a defined distance from their data points
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace(distance = 2)
 # braces starting at a defined point
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace(outerstart = 5)
 # braces starting at a defined point and with defined width
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace(outerstart = 5, width = 1)
 # braces starting at a defined point and with defined width and defined curve bending
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace(outerstart = 5, width = 1, bending = 0.1)
 # braces outside of the plotting area
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace(outerstart = 4.5) +
 coord_cartesian(y=range(iris$Sepal.Width), clip = "off") +
 theme(plot.margin = unit(c(0.25, 0.11, 0.11, 0.11), units="npc"))
 # braces with discrete axes
 df <- iris
 df$Group <- substring(iris$Species,1,1)
 ggplot(df, aes(x=Species, y=Sepal.Length, group=Group)) +
   geom_jitter() +
   stat_brace(discreteAxis=TRUE)
create text for curly braces as a layer in ggplot
Description
Imports: ggplot2
Usage
stat_bracetext(
  mapping = NULL,
  data = NULL,
  geom = "text",
  position = "identity",
  ...,
  rotate = 0,
  width = NULL,
  mid = NULL,
  outside = TRUE,
  distance = NULL,
  outerstart = NULL,
  textdistance = NULL,
  show.legend = FALSE,
  inherit.aes = TRUE
)
Arguments
mapping | 
 Set of aesthetic mappings created by   | 
data | 
 The data to be displayed in this layer. There are three options: If  A  A   | 
geom | 
 The geometric object to use to display the data for this layer.
When using a  
  | 
position | 
 A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The  
  | 
... | 
 Other arguments passed on to  
  | 
rotate | 
 number in degrees. Defines where the brace points to: 0=up (default), 90=right, 180=down, 270=left  | 
width | 
 number. Distance from the brace's start to its tip. If NULL (default), will be determined by data.  | 
mid | 
 number from 0.25 to 0.75. Position of the pointer within the brace space. If NULL (default), will be determined by data.  | 
outside | 
 boolean. If TRUE (default), brace is next to the data area. If FALSE, brace is inside the data area  | 
distance | 
 number. Space between the brace and the nearest data point. If NULL (default), will be determined by data.  | 
outerstart | 
 number. If not NULL, overwrites distance and sets all braces to the same origin  | 
textdistance | 
 number. Distance of the label to the brace pointer  | 
show.legend | 
 logical. Should this layer be included in the legends?
  | 
inherit.aes | 
 If   | 
Value
ggplot2 layer object (geom_text or geom_label) that can directly be added to a ggplot2 object.
Examples
library(ggbrace)
library(ggplot2)
data(iris)
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) +
 geom_point() +
 stat_brace() +
 stat_bracetext()