Draws a hand-drawn bracket spanning xmin to xmax at height y, with short
tips dropping toward the data and an optional label (e.g. a p-value or
"n.s.") centred above. It is the sketch counterpart of a ggsignif bracket:
useful for marking pairwise comparisons on boxplots, bars, or violins.
GeomSketchBracketgeom_sketch_bracket(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
tip_length = 0.02,
family = NULL,
label_vjust = -0.35,
roughness = 0.8,
bowing = 0.4,
n_passes = 2L,
seed = NULL,
na.rm = FALSE,
show.legend = FALSE,
inherit.aes = FALSE
)
A ggplot2 layer object.
Aesthetic mappings created by ggplot2::aes(). Requires
xmin, xmax, and y; label is optional.
Data with one row per bracket.
Statistical transformation. Default "identity".
Position adjustment. Default "identity".
Other arguments passed on to the layer.
Length of the downward end tips, as a fraction of panel
height. Default 0.02. Use 0 for a plain bar.
Font family for the label. Defaults to the same family as
theme_sketch() (getOption("ggsketch.base_family", ""), i.e. the device
default), so the label matches the plot's other text; set
options(ggsketch.base_family = "auto") for a handwriting face, or pass an
explicit family here.
Vertical justification of the label relative to the bar
(negative nudges it above). Default -0.35.
Non-negative roughness (0 = straight). Default 0.8.
Non-negative bowing multiplier. Default 0.4 (kept low so the bar stays readable).
Number of stroke passes. Default 2.
Integer seed. NULL uses getOption("ggsketch.seed", 1L).
Remove missing values silently? Default FALSE.
Logical; include in legend? Default FALSE.
Inherit aesthetics from the plot? Default FALSE.
Brackets are usually one-off annotations, so supply them with their own
data and inherit.aes = FALSE rather than inheriting the plot's mapping.
Other sketch-geoms:
GeomSketchAbline,
GeomSketchArrow,
GeomSketchBoxplot,
GeomSketchCallout,
GeomSketchChicklet,
GeomSketchCol,
GeomSketchContourFilled,
GeomSketchCurve,
GeomSketchDotplot,
GeomSketchDumbbell,
GeomSketchEdge,
GeomSketchEllipse,
GeomSketchEngrave,
GeomSketchGantt,
GeomSketchHex,
GeomSketchLine,
GeomSketchLinerange,
GeomSketchLollipop,
GeomSketchMarkCircle,
GeomSketchMarkHull,
GeomSketchPath,
GeomSketchPoint,
GeomSketchPolygon,
GeomSketchRect,
GeomSketchRibbon,
GeomSketchRug,
GeomSketchSegment,
GeomSketchSfPolygon,
GeomSketchSlope,
GeomSketchSmooth,
GeomSketchSpoke,
GeomSketchTextRepel,
GeomSketchViolin,
StatSketchBeeswarm,
StatSketchCalendar,
StatSketchDensityRidges,
StatSketchFunnel,
StatSketchPie,
StatSketchPyramid,
StatSketchRadar,
StatSketchStream,
StatSketchTreemap,
StatSketchWaffle,
StatSketchWaterfall,
annotate_sketch(),
annotate_sketch_arrow(),
annotate_sketch_callout(),
annotate_sketch_highlight(),
geom_sketch_alluvial(),
geom_sketch_arc_diagram(),
geom_sketch_bin2d(),
geom_sketch_bump(),
geom_sketch_chord(),
geom_sketch_contour(),
geom_sketch_count(),
geom_sketch_dendrogram(),
geom_sketch_density(),
geom_sketch_density2d(),
geom_sketch_ecdf(),
geom_sketch_function(),
geom_sketch_histogram(),
geom_sketch_jitter(),
geom_sketch_marimekko(),
geom_sketch_mosaic(),
geom_sketch_parallel(),
geom_sketch_qq(),
geom_sketch_quantile(),
geom_sketch_rose(),
geom_sketch_sunburst(),
geom_sketch_text(),
sketch_graph()
library(ggplot2)
brackets <- data.frame(xmin = 1, xmax = 2, y = 45, label = "p = 0.01")
ggplot(mpg, aes(drv, hwy)) +
geom_sketch_boxplot(seed = 1L) +
geom_sketch_bracket(
data = brackets,
aes(xmin = xmin, xmax = xmax, y = y, label = label),
family = "", seed = 2L
) +
theme_sketch()
Run the code above in your browser using DataLab