| Title: | Curly Braces for 'ggplot2' |
|---|---|
| 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(). |
| Authors: | Nicolas Huber [aut, cre, cph] |
| Maintainer: | Nicolas Huber <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-06-03 08:33:29 UTC |
| Source: | https://github.com/nicolash2/ggbrace |
Imports: stats
.coordCorrection( x, y, rotate, mid, textdistance = NULL, distance, outerstart, width, outside, bending, discreteAxis = FALSE ).coordCorrection( x, y, rotate, mid, textdistance = NULL, distance, outerstart, width, outside, bending, discreteAxis = FALSE )
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
.seekBrace(x, y, rotate, bending, npoints, bracketType).seekBrace(x, y, rotate, bending, npoints, bracketType)
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" |
Imports: ggplot2
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 )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 )
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. |
ggplot2 layer object (geom_path) that can directly be added to a ggplot2 object.
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)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)
Imports: ggplot2
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 )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 )
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 |
ggplot2 layer object (geom_text or geom_label) that can directly be added to a ggplot2 object.
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()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()