| Title: | Publication-Quality 'ggplot2' Annotation |
| Version: | 0.2.0 |
| Description: | Annotation helper functions for publication-quality 'ggplot2' visualisation. These functions make it easier to annotate plots in a way that stays consistent with the set theme. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/davidhodge931/ggscribe, https://davidhodge931.github.io/ggscribe/ |
| BugReports: | https://github.com/davidhodge931/ggscribe/issues |
| Depends: | R (≥ 4.1.0) |
| Imports: | blends, farver, ggplot2 (≥ 4.0.0), grid, rlang, scales, vctrs |
| Encoding: | UTF-8 |
| Language: | en-GB |
| Suggests: | dplyr, flexoki, ggrefine, ggwidth, jumble, knitr, rmarkdown, spelling, stringr |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-07-07 02:18:17 UTC; david |
| Author: | David Hodge |
| Maintainer: | David Hodge <davidhodge931@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-07 02:40:02 UTC |
ggscribe: Publication-Quality 'ggplot2' Annotation
Description
Annotation helper functions for publication-quality 'ggplot2' visualisation. These functions make it easier to annotate plots in a way that stays consistent with the set theme.
Author(s)
Maintainer: David Hodge davidhodge931@gmail.com (ORCID) [copyright holder]
Authors:
David Hodge davidhodge931@gmail.com (ORCID) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/davidhodge931/ggscribe/issues
A mapped aesthetic for text colour on fill
Description
Modifies a mapped colour (or fill) aesthetic for contrast against the fill (or colour) aesthetic.
Function can be spliced into ggplot2::aes with rlang::!!!.
Usage
aes_contrast(..., dark = NULL, light = NULL, aesthetic = "colour")
Arguments
... |
Unused. Included to support a trailing comma. |
dark |
A dark colour. If NULL, derived from theme text or panel background. |
light |
A light colour. If NULL, derived from theme text or panel background. |
aesthetic |
The aesthetic to be modified for contrast. Either |
Value
A ggplot2 mapping object suitable for use in ggplot2::aes() or as a
mapping = argument in a layer.
Annotate an axis bracket
Description
Draws one or more brackets along a floating axis line. Each bracket spans
min(breaks) to max(breaks) with caps at every break value.
Requires coord_cartesian(clip = "off").
Usage
axis_bracket(
xintercept = NULL,
yintercept = NULL,
breaks,
length = ggplot2::rel(1),
colour = NULL,
linewidth = NULL,
linetype = NULL,
layout = NULL
)
Arguments
xintercept |
One or more x positions for vertical axis lines, in data
coordinates or wrapped in |
yintercept |
One or more y positions for horizontal axis lines, in data
coordinates or wrapped in |
breaks |
A numeric vector of length >= 2 in data coordinates, or
wrapped in |
length |
Length of the bracket caps. Supports |
colour |
Inherits from |
linewidth |
Inherits from |
linetype |
Inherits from |
layout |
Controls which panels the annotation appears in. |
Details
Caps always point in the positive direction by default (right for
xintercept, up for yintercept). Use a negative length to flip them
(e.g. length = -rel(1)).
Value
A list of ggplot2 annotation layers.
Annotate an axis line
Description
Draws a full line at one or more floating positions, with style defaults
taken from the axis.line element of the set theme. Requires
coord_cartesian(clip = "off").
Usage
axis_line(
xintercept = NULL,
yintercept = NULL,
colour = NULL,
linewidth = NULL,
linetype = NULL,
arrow = NULL,
layout = NULL
)
Arguments
xintercept |
One or more x positions for vertical axis lines, in data
coordinates or wrapped in |
yintercept |
One or more y positions for horizontal axis lines, in data
coordinates or wrapped in |
colour |
Inherits from |
linewidth |
Inherits from |
linetype |
Inherits from |
arrow |
A |
layout |
Controls which panels the annotation appears in. |
Details
The arrow (if any) points in the positive direction by default — rightward
for xintercept lines, upward for yintercept lines.
Value
A list of ggplot2 annotation layers.
Annotate axis text
Description
Draws text labels at specified break positions along a floating axis line,
with style defaults taken from the axis.text element of the set theme.
Requires coord_cartesian(clip = "off").
Usage
axis_text(
xintercept = NULL,
yintercept = NULL,
breaks,
labels = NULL,
length = ggplot2::rel(1),
angle = 0,
hjust = NULL,
vjust = NULL,
colour = NULL,
size = NULL,
family = NULL,
layout = NULL
)
Arguments
xintercept |
One or more x positions for vertical axis lines, in data
coordinates or wrapped in |
yintercept |
One or more y positions for horizontal axis lines, in data
coordinates or wrapped in |
breaks |
A numeric vector of break positions in data coordinates, or
wrapped in |
labels |
One of:
|
length |
Offset from the axis line including tick length and margin.
Supports |
angle |
Text rotation angle. Defaults to |
hjust, vjust |
Justification. Auto-calculated from axis direction and
|
colour |
Inherits from |
size |
Inherits from |
family |
Inherits from |
layout |
Controls which panels the annotation appears in. |
Details
Text always sits on the positive side of the axis by default (right of
xintercept lines, above yintercept lines). Use a negative length
to place text on the opposite side (e.g. length = -rel(1)).
Value
A list of ggplot2 annotation layers.
Annotate axis ticks
Description
Draws axis ticks at specified break positions along a floating axis line.
Requires coord_cartesian(clip = "off").
Usage
axis_ticks(
xintercept = NULL,
yintercept = NULL,
breaks,
length = ggplot2::rel(1),
colour = NULL,
linewidth = NULL,
linetype = NULL,
arrow = NULL,
layout = NULL
)
Arguments
xintercept |
One or more x positions for vertical axis lines, in data
coordinates or wrapped in |
yintercept |
One or more y positions for horizontal axis lines, in data
coordinates or wrapped in |
breaks |
A numeric vector of break positions in data coordinates, or
wrapped in |
length |
Total tick length. Supports |
colour |
Inherits from |
linewidth |
Inherits from |
linetype |
Inherits from |
arrow |
A |
layout |
Controls which panels the annotation appears in. |
Details
Ticks always point in the positive direction by default (right for
xintercept, up for yintercept). Use a negative length to flip them
(e.g. length = -rel(1)).
Value
A list of ggplot2 annotation layers.
Guide optimised for secondary axis text annotations
Description
A wrapper around ggplot2::guide_axis() that defaults to making transparent
ticks and lines while preserving text, making it ideal for annotation labels.
Usage
guide_sec_axis_text(..., theme = NULL)
Arguments
... |
Additional arguments passed to |
theme |
A theme object to style the secondary axis. |
Value
A guide object to be used in a scale's guide argument or within
sec_axis_text().
Annotate a panel background region
Description
Draws filled rectangles over the panel. Defaults to the panel.background
fill from the set theme at full opacity, making it useful for layering a
solid background over existing content. Should be placed before geom layers.
Usage
panel_background(
xmin = -Inf,
xmax = Inf,
ymin = -Inf,
ymax = Inf,
fill = NULL,
alpha = 1,
colour = NULL,
linewidth = NULL,
linetype = 0,
layout = NULL
)
Arguments
xmin, xmax |
Left and right edges of the rectangle in data coordinates.
Defaults to |
ymin, ymax |
Bottom and top edges of the rectangle in data coordinates.
Defaults to |
fill |
Fill colour. Defaults to the |
alpha |
Opacity. Defaults to |
colour |
Border colour. Defaults to the resolved |
linewidth |
Inherits from |
linetype |
Border linetype. Defaults to |
layout |
Controls which panels the annotation appears in. |
Value
A list containing annotation layers.
Annotate panel gridlines
Description
Draws gridlines at specified positions, with style defaults taken from the
panel.grid.major element of the set theme. Crop bounds (xmin, xmax,
ymin, ymax) both filter which lines are drawn and control how far they
run across the panel.
Usage
panel_grid(
xintercept = NULL,
yintercept = NULL,
xmin = -Inf,
xmax = Inf,
ymin = -Inf,
ymax = Inf,
colour = NULL,
linewidth = NULL,
linetype = NULL,
layout = NULL
)
Arguments
xintercept |
One or more x positions for vertical gridlines, in data
coordinates or wrapped in |
yintercept |
One or more y positions for horizontal gridlines, in data
coordinates or wrapped in |
xmin, xmax |
Left and right crop bounds. Vertical gridlines outside
|
ymin, ymax |
Bottom and top crop bounds. Horizontal gridlines outside
|
colour |
Inherits from |
linewidth |
Inherits from |
linetype |
Inherits from |
layout |
Controls which panels the annotation appears in. |
Value
A list of ggplot2 annotation layers.
Annotate a shaded panel region
Description
A convenience wrapper around panel_background() with a smart shade default
which blends the panel background fill with jumble::slate at 25% opacity
with no border. Should be placed before geom layers.
Usage
panel_shade(
xmin = -Inf,
xmax = Inf,
ymin = -Inf,
ymax = Inf,
fill = NULL,
alpha = 0.2,
colour = "transparent",
linewidth = NULL,
linetype = 1,
layout = NULL
)
Arguments
xmin, xmax |
Left and right edges of the rectangle in data coordinates.
Defaults to |
ymin, ymax |
Bottom and top edges of the rectangle in data coordinates.
Defaults to |
fill |
Fill colour. |
alpha |
Opacity. Defaults to |
colour |
Border colour. Defaults to |
linewidth |
Inherits from |
linetype |
Border linetype. Defaults to |
layout |
Controls which panels the annotation appears in. |
Value
A list containing annotation layers.
Annotate a reference line
Description
Draws one or more reference lines within the panel, with style defaults
taken from the axis.line element of the set theme.
Usage
reference_line(
xintercept = NULL,
yintercept = NULL,
colour = NULL,
linewidth = NULL,
linetype = "dashed",
arrow = NULL,
layout = NULL
)
Arguments
xintercept |
One or more x positions for vertical reference lines, in
data coordinates or wrapped in |
yintercept |
One or more y positions for horizontal reference lines, in
data coordinates or wrapped in |
colour |
Inherits from |
linewidth |
Inherits from |
linetype |
Defaults to |
arrow |
A |
layout |
Controls which panels the annotation appears in. |
Details
The arrow (if any) points in the positive direction by default — rightward
for xintercept lines, upward for yintercept lines.
Value
A list of ggplot2 annotation layers.
Secondary axis for text annotations
Description
Secondary axis for text annotations
Usage
sec_axis_text(
breaks = function(x) mean(x),
labels = ggplot2::waiver(),
name = NULL,
guide = guide_sec_axis_text(),
...
)
Arguments
breaks |
A function or numeric vector giving the break position(s) used
to anchor the text. Defaults to |
labels |
One of:
|
name |
The name of the secondary axis. Use |
guide |
A guide object used to render the axis. Defaults to
|
... |
Additional arguments passed to |
Value
A AxisSecondary object for use in the sec.axis argument of
scale_x_continuous() or scale_y_continuous().