Package {ggwidth}


Title: Publication-Quality 'ggplot2' Geom Width
Version: 0.1.2
Description: Width helper functions for publication-quality 'ggplot2' visualisation. These functions make it easier to create geoms such as bars that have a consistent width appearance across plots.
License: MIT + file LICENSE
URL: https://github.com/davidhodge931/ggwidth, https://davidhodge931.github.io/ggwidth/
BugReports: https://github.com/davidhodge931/ggwidth/issues
Depends: R (≥ 4.1.0)
Imports: ggplot2 (≥ 4.0.0), grid, rlang
Suggests: dplyr, forcats, patchwork, testthat (≥ 3.0.0), tibble, withr
Encoding: UTF-8
Language: en-GB
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
NeedsCompilation: no
Packaged: 2026-07-07 00:11:47 UTC; david
Author: David Hodge ORCID iD [aut, cre, cph]
Maintainer: David Hodge <davidhodge931@gmail.com>
Repository: CRAN
Date/Publication: 2026-07-07 02:10:02 UTC

ggwidth: Publication-Quality 'ggplot2' Geom Width

Description

logo

Width helper functions for publication-quality 'ggplot2' visualisation. These functions make it easier to create geoms such as bars that have a consistent width appearance across plots.

Author(s)

Maintainer: David Hodge davidhodge931@gmail.com (ORCID) [copyright holder]

Authors:

See Also

Useful links:


Standardise ggplot2 geom width

Description

Standardise the width in ggplot2 geoms so that widths appear visually consistent across plots with different numbers of categories, panel dimensions, and orientations.

This can be used in geoms such as ggplot2::geom_bar(), ggplot2::geom_col(), ggplot2::geom_boxplot(), and ggplot2::geom_errorbar().

The relevant panel dimension must be an absolute physical unit (for example grid::unit(..., "mm")), either supplied directly or set in the current theme. Relative units are not supported.

Usage

get_width(
  ...,
  n = NULL,
  n_dodge = NULL,
  orientation = c("x", "y"),
  equiwidth = NULL,
  panel_widths = NULL,
  panel_heights = NULL
)

Arguments

...

Must be empty. Forces all other arguments to be named and allows trailing commas.

n

Number of categories in the orientation aesthetic (that is, "x" or "y"). For faceted plots, use the maximum n across facets.

n_dodge

Number of dodge categories. Intended for use with position_dodge(preserve = "single").

orientation

Orientation: "x" for vertical geoms, "y" for horizontal geoms.

equiwidth

Numeric scaling factor controlling apparent width. A value of 1 is the default. Increase to make a wider appearance; decrease to make a thinner appearance. If NULL, uses the value set by set_equiwidth(), falling back to 1.

panel_widths

A grid::unit object specifying panel widths. If NULL, uses the value from the current theme.

panel_heights

A grid::unit object specifying panel heights. If NULL, uses the value from the current theme.

Value

A single numeric width suitable for the width argument of geoms such as ggplot2::geom_bar() or ggplot2::geom_col().


Set a global equiwidth

Description

Set a global default for the equiwidth argument used by get_width().

Usage

set_equiwidth(equiwidth = 1)

Arguments

equiwidth

A single positive finite numeric value.

Value

The previous option value, invisibly.