Package 'ggblanket'

Title: Simplify 'ggplot2' Visualisation
Description: Simplify 'ggplot2' visualisation with 'ggblanket' wrapper functions.
Authors: David Hodge [aut, cre, cph]
Maintainer: David Hodge <[email protected]>
License: MIT + file LICENSE
Version: 11.0.0
Built: 2024-11-25 15:09:49 UTC
Source: CRAN

Help Index


A colour aesthetic for contrast

Description

A colour aesthetic to contrast with a fill aesthetic. Can be spliced into ggplot2::aes with rlang::!!!.

Usage

aes_colour_contrast(..., dark = "#121B24FF", light = "#FFFFFFFF")

Arguments

...

Provided to force user argument naming etc.

dark

A dark colour.

light

A light colour.

Value

A ggplot2 aesthetic

Examples

library(ggplot2)
library(dplyr)
library(stringr)
library(palmerpenguins)

set_blanket()

penguins |>
  count(species, sex) |>
  gg_col(
    x = sex,
    y = n,
    col = species,
    label = n,
    position = position_dodge(preserve = "single"),
    width = 0.75,
    x_labels = \(x) str_to_sentence(x),
  ) +
  geom_text(
    mapping = aes_colour_contrast(),
    position = position_dodge(width = 0.75, preserve = "single"),
    vjust = 1.33,
    show.legend = FALSE,
  )

penguins |>
  count(species, sex) |>
  gg_col(
    x = sex,
    y = n,
    col = species,
    position = position_dodge(preserve = "single"),
    width = 0.75,
    x_labels = \(x) str_to_sentence(x),
    mode = dark_mode_r(),
  ) +
  geom_text(
    mapping = aes(label = n, !!!aes_colour_contrast(dark = darkness[3], light = darkness[1])),
    position = position_dodge(width = 0.75, preserve = "single"),
    vjust = 1.33,
    show.legend = FALSE,
  )

Lighten/darken a colour/fill aesthetic

Description

Lighten/darken a colour/fill aesthetic based on a

  • aes_colour_darken() Darken a colour aesthetic, relative to a fill aesthetic

  • aes_colour_lighten() Lighten a colour aesthetic, relative to the fill aesthetic

  • aes_fill_darken() Darken a fill aesthetic, relative to a colour aesthetic

  • aes_fill_lighten() Lighten a fill aesthetic, relative to the colour aesthetic Can be spliced into ggplot2::aes with rlang::!!!.

Usage

aes_colour_darken(..., amount = 0.1)

aes_colour_lighten(..., amount = 0.1)

aes_fill_darken(..., amount = 0.1)

aes_fill_lighten(..., amount = 0.1)

Arguments

...

Other arguments passed to colorspace::darken()/colorspace::lighten().

amount

Numeric specifying the amount of lightening or darkening.

Value

A ggplot2 aesthetic

Examples

library(ggblanket)
library(ggplot2)
library(palmerpenguins)

set_blanket(
  alpha_recursive = 1,
)

penguins |>
  gg_bar(
    y = species,
    col = island,
    mapping = aes_colour_darken(amount = 0.2),
    width = 0.75,
  )

penguins |>
gg_bar(
  y = species,
  col = island,
  mapping = aes(!!!aes_colour_darken(amount = 0.2)),
  width = 0.75,
)

A blue colour

Description

A blue colour.

Usage

blue

Value

A character vector.

Examples

scales::show_col(blue)

Dark mode theme family

Description

A dark mode family of functions:

  • dark_mode_r() with legend on right

  • dark_mode_t() with legend on top

  • dark_mode_b() with legend on bottom

Usage

dark_mode_r(
  ...,
  base_size = 11,
  base_family = "",
  base_colour = "#C8D7DFFF",
  axis_line_colour = "#C8D7DFFF",
  axis_line_linewidth = 0.33,
  axis_ticks_colour = axis_line_colour,
  axis_ticks_linewidth = axis_line_linewidth,
  panel_grid_colour = "#00040AFF",
  panel_grid_linewidth = 1.33,
  panel_background_fill = "#050D1BFF",
  plot_background_fill = "#00040AFF",
  legend_axis_line_colour = plot_background_fill,
  legend_axis_line_linewidth = 0.33,
  legend_background_fill = plot_background_fill,
  legend_key_fill = plot_background_fill,
  legend_ticks_colour = legend_axis_line_colour,
  legend_ticks_linewidth = legend_axis_line_linewidth,
  legend_ticks_length = ggplot2::rel(c(0.175, 0))
)

dark_mode_t(
  ...,
  base_size = 11,
  base_family = "",
  base_colour = "#C8D7DFFF",
  axis_line_colour = "#C8D7DFFF",
  axis_line_linewidth = 0.33,
  axis_ticks_colour = axis_line_colour,
  axis_ticks_linewidth = axis_line_linewidth,
  panel_grid_colour = "#00040AFF",
  panel_grid_linewidth = 1.33,
  panel_background_fill = "#050D1BFF",
  plot_background_fill = "#00040AFF",
  legend_axis_line_colour = plot_background_fill,
  legend_axis_line_linewidth = 0.33,
  legend_background_fill = plot_background_fill,
  legend_key_fill = plot_background_fill,
  legend_ticks_colour = legend_axis_line_colour,
  legend_ticks_linewidth = legend_axis_line_linewidth,
  legend_ticks_length = ggplot2::rel(c(0.175, 0))
)

dark_mode_b(
  ...,
  base_size = 11,
  base_family = "",
  base_colour = "#C8D7DFFF",
  axis_line_colour = "#C8D7DFFF",
  axis_line_linewidth = 0.33,
  axis_ticks_colour = axis_line_colour,
  axis_ticks_linewidth = axis_line_linewidth,
  panel_grid_colour = "#00040AFF",
  panel_grid_linewidth = 1.33,
  panel_background_fill = "#050D1BFF",
  plot_background_fill = "#00040AFF",
  legend_axis_line_colour = plot_background_fill,
  legend_axis_line_linewidth = 0.33,
  legend_background_fill = plot_background_fill,
  legend_key_fill = plot_background_fill,
  legend_ticks_colour = legend_axis_line_colour,
  legend_ticks_linewidth = legend_axis_line_linewidth,
  legend_ticks_length = ggplot2::rel(c(0.175, 0))
)

Arguments

...

Provided to force user argument naming etc.

base_size

The base size of the text theme element. Defaults to 11.

base_family

The base family of the text theme element. Defaults to "".

base_colour

The base colour of the text theme element.

axis_line_colour

The colour of the axis.line theme element.

axis_line_linewidth

The linewidth of the axis.line theme element.

axis_ticks_colour

The colour of the axis.ticks theme element.

axis_ticks_linewidth

The linewidth of the axis.ticks theme element.

panel_grid_colour

The colour of the panel.grid theme element.

panel_grid_linewidth

The linewidth of the panel.grid theme element.

panel_background_fill

The fill (and colour) of the panel.background theme element.

plot_background_fill

The fill (and colour) of the plot.background theme element.

legend_axis_line_colour

The colour of the legend.axis.line theme element.

legend_axis_line_linewidth

The linewidth of the legend.axis.line theme element.

legend_background_fill

The fill (and colour) of the legend.background theme element.

legend_key_fill

The fill (and colour) of the legend.key theme element.

legend_ticks_colour

The colour of the legend.ticks theme element.

legend_ticks_linewidth

The linewidth of the legend.ticks theme element.

legend_ticks_length

The legend.ticks.length theme element.

Value

A ggplot theme.

Examples

library(palmerpenguins)
library(ggplot2)

set_blanket()

penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
    mode = dark_mode_r()
  )

 penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
    mode = dark_mode_t()
  )

 penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
    mode = dark_mode_b()
  )

Area ggplot

Description

Create an area ggplot with a wrapper around ggplot2::ggplot() + geom_area().

Usage

gg_area(
  data = NULL,
  ...,
  stat = "align",
  position = "stack",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

economics |>
  gg_area(
    x = date,
    y = unemploy,
    y_label = "Unemployment",
  )

Bar ggplot

Description

Create a bar ggplot with a wrapper around ggplot2::ggplot() + geom_bar().

Usage

gg_bar(
  data = NULL,
  ...,
  stat = "count",
  position = "stack",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_bar(
    y = species,
    width = 0.75,
  )

Bin_2d ggplot

Description

Create a bin2d ggplot with a wrapper around ggplot2::ggplot() + geom_bin_2d().

Usage

gg_bin_2d(
  data = NULL,
  ...,
  stat = "bin2d",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

diamonds |>
  gg_bin_2d(
    x = carat,
    y = price,
  )

Blanket ggplot

Description

Create a blanket ggplot with a wrapper around ggplot2::ggplot() + layer() with geom_blank() defaults. This function underlies all other ⁠gg_*⁠ functions. It contains a geom argument for maximum flexibility.

Usage

gg_blanket(
  data = NULL,
  ...,
  geom = "blank",
  stat = "identity",
  position = "identity",
  coord = NULL,
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

geom

A geometric object to display the data. A snakecase character string of a ggproto Geom subclass object minus the Geom prefix (e.g. "point").

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins %>%
  gg_blanket(
    geom = "violin",
    stat = "ydensity",
    position = "dodge",
    x = species,
    y = body_mass_g,
    col = sex,
  )

Boxplot ggplot

Description

Create a boxplot ggplot with a wrapper around ggplot2::ggplot() + geom_boxplot().

Usage

gg_boxplot(
  data = NULL,
  ...,
  stat = "boxplot",
  position = "dodge2",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_boxplot(
    x = flipper_length_mm,
    y = species,
    col = sex,
  )

Col ggplot

Description

Create a col ggplot with a wrapper around ggplot2::ggplot() + geom_col().

Usage

gg_col(
  data = NULL,
  ...,
  stat = "identity",
  position = "stack",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  tidyr::drop_na(sex) |>
  group_by(sex, species) |>
  summarise(across(flipper_length_mm, \(x) mean(x, na.rm = TRUE))) |>
  gg_col(
    x = flipper_length_mm,
    y = species,
    col = sex,
    position = position_dodge(preserve = "single"),
    width = 0.75,
  )

Contour ggplot

Description

Create a contour ggplot with a wrapper around ggplot2::ggplot() + geom_contour().

Usage

gg_contour(
  data = NULL,
  ...,
  stat = "contour",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

ggplot2::faithfuld |>
  gg_contour(
    x = waiting,
    y = eruptions,
    z = density,
  )

Contour_filled ggplot

Description

Create a contour_filled ggplot with a wrapper around ggplot2::ggplot() + geom_contour_filled().

Usage

gg_contour_filled(
  data = NULL,
  ...,
  stat = "contour_filled",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

faithfuld |>
  gg_contour_filled(
    x = waiting,
    y = eruptions,
    z = density,
    bins = 8,
  )

Crossbar ggplot

Description

Create a crossbar ggplot with a wrapper around ggplot2::ggplot() + geom_crossbar().

Usage

gg_crossbar(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
) |>
  gg_crossbar(
    x = trt,
    y = resp,
    ymin = lower,
    ymax = upper,
    col = group,
    width = 0.5,
    x_label = "Treatment",
    y_label = "Response",
  )

Density ggplot

Description

Create a density ggplot with a wrapper around ggplot2::ggplot() + geom_density().

Usage

gg_density(
  data = NULL,
  ...,
  stat = "density",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_density(
    x = flipper_length_mm,
    col = species,
  )

Density_2d ggplot

Description

Create a density_2d ggplot with a wrapper around ggplot2::ggplot() + geom_density_2d().

Usage

gg_density_2d(
  data = NULL,
  ...,
  stat = "density_2d",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

faithful |>
  gg_density_2d(
    x = waiting,
    y = eruptions,
    bins = 8,
    contour = TRUE,
  )

Density_2d_filled ggplot

Description

Create a density_2d_filled ggplot with a wrapper around ggplot2::ggplot() + geom_density_2d_filled().

Usage

gg_density_2d_filled(
  data = NULL,
  ...,
  stat = "density_2d_filled",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

faithful |>
  gg_density_2d_filled(
    x = waiting,
    y = eruptions,
    bins = 8,
    contour = TRUE,
  )

Errorbar ggplot

Description

Create a errorbar ggplot with a wrapper around ggplot2::ggplot() + geom_errorbar().

Usage

gg_errorbar(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
) |>
  gg_errorbar(
    x = trt,
    ymin = lower,
    ymax = upper,
    col = group,
    width = 0.1,
    x_label = "Treatment",
    y_label = "Response",
  )

Freqpoly ggplot

Description

Create a freqpoly ggplot with a wrapper around ggplot2::ggplot() + geom_freqpoly().

Usage

gg_freqpoly(
  data = NULL,
  ...,
  stat = "bin",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_freqpoly(
    x = flipper_length_mm,
    col = sex,
  )

Function ggplot

Description

Create a function ggplot with a wrapper around ggplot2::ggplot() + geom_function().

Usage

gg_function(
  data = NULL,
  ...,
  stat = "function",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

gg_function(
  fun = \(x) dnorm(x, mean = 0, sd = 5),
  x_expand_limits = qnorm(p = c(0.005, 0.995), mean = 0, sd = 5),
  y_expand_limits = 0,
)

Hex ggplot

Description

Create a hex ggplot with a wrapper around ggplot2::ggplot() + geom_hex().

Usage

gg_hex(
  data = NULL,
  ...,
  stat = "binhex",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

diamonds |>
  gg_hex(
    x = carat,
    y = price,
  )

Histogram ggplot

Description

Create a histogram ggplot with a wrapper around ggplot2::ggplot() + geom_histogram().

Usage

gg_histogram(
  data = NULL,
  ...,
  stat = "bin",
  position = "stack",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = sex,
    bins = 50,
  )

Jitter ggplot

Description

Create a jitter ggplot with a wrapper around ggplot2::ggplot() + geom_jitter().

Usage

gg_jitter(
  data = NULL,
  ...,
  stat = "identity",
  position = "jitter",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

set.seed(123)

penguins |>
  gg_jitter(
    x = species,
    y = body_mass_g,
    col = flipper_length_mm,
    position = position_jitter(height = 0),
    y_expand_limits = 0,
    col_steps = TRUE,
  )

Label ggplot

Description

Create a label ggplot with a wrapper around ggplot2::ggplot() + geom_label().

Usage

gg_label(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

bind_rows(
  mtcars |> slice_min(order_by = mpg),
  mtcars |> slice_max(order_by = mpg)
) |>
  tibble::rownames_to_column("model") |>
  gg_label(
    x = model,
    y = mpg,
    col = mpg,
    label = model,
    y_expand_limits = 0,
    y_label = "Miles per gallon",
    col_palette = c(orange, "white", teal),
  )

Line ggplot

Description

Create a line ggplot with a wrapper around ggplot2::ggplot() + geom_line().

Usage

gg_line(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

economics |>
  gg_line(
    x = date,
    y = unemploy,
    y_expand_limits = 0,
    y_label = "Unemployment",
  )

Linerange ggplot

Description

Create a linerange ggplot with a wrapper around ggplot2::ggplot() + geom_linerange().

Usage

gg_linerange(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
) |>
  gg_linerange(
    x = trt,
    ymin = lower,
    ymax = upper,
    col = group,
    position = position_dodge(width = 0.2),
    x_label = "Treatment",
    y_label = "Response",
  )

Path ggplot

Description

Create a path ggplot with a wrapper around ggplot2::ggplot() + geom_path().

Usage

gg_path(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

economics |>
  mutate(unemploy_rate = unemploy / pop) |>
  gg_path(
    x = unemploy_rate,
    y = psavert,
    x_label = "Unemployment rate",
    y_expand_limits = 0,
    y_label = "Personal savings rate",
  )

Point ggplot

Description

Create a point ggplot with a wrapper around ggplot2::ggplot() + geom_point().

Usage

gg_point(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
  )

Pointrange ggplot

Description

Create a pointrange ggplot with a wrapper around ggplot2::ggplot() + geom_pointrange().

Usage

gg_pointrange(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
) |>
  gg_pointrange(
    x = trt,
    y = resp,
    col = group,
    ymin = lower,
    ymax = upper,
    position = position_dodge(width = 0.2),
    x_label = "Treatment",
    y_label = "Response",
  )

Polygon ggplot

Description

Create a polygon ggplot with a wrapper around ggplot2::ggplot() + geom_polygon().

Usage

gg_polygon(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

ids <- factor(c("1.1", "2.1", "1.2", "2.2", "1.3", "2.3"))

values <- data.frame(
  id = ids,
  value = c(3, 3.1, 3.1, 3.2, 3.15, 3.5)
)

positions <- data.frame(
  id = rep(ids, each = 4),
  x = c(
    2, 1, 1.1, 2.2, 1, 0, 0.3, 1.1, 2.2, 1.1, 1.2, 2.5, 1.1, 0.3,
    0.5, 1.2, 2.5, 1.2, 1.3, 2.7, 1.2, 0.5, 0.6, 1.3
  ),
  y = c(
    -0.5, 0, 1, 0.5, 0, 0.5, 1.5, 1, 0.5, 1, 2.1, 1.7, 1, 1.5,
    2.2, 2.1, 1.7, 2.1, 3.2, 2.8, 2.1, 2.2, 3.3, 3.2
  )
)

datapoly <- merge(values, positions, by = c("id"))

datapoly |>
  gg_polygon(
    x = x,
    y = y,
    col = value,
    group = id,
  )

Qq ggplot

Description

Create a qq ggplot with a wrapper around ggplot2::ggplot() + geom_qq().

Usage

gg_qq(
  data = NULL,
  ...,
  stat = "qq",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_qq(
    sample = body_mass_g,
    facet = species,
    coord = coord_cartesian(clip = "on"),
  ) +
  geom_qq_line()

Quantile ggplot

Description

Create an quantile ggplot with a wrapper around ggplot2::ggplot() + geom_quantile().

Usage

gg_quantile(
  data = NULL,
  ...,
  stat = "quantile",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

if (requireNamespace("quantreg", quietly = TRUE)) {
  library(ggplot2)
  library(palmerpenguins)

  set_blanket()

  penguins |>
    gg_quantile(
      x = flipper_length_mm,
      y = body_mass_g,
    )
}

Raster ggplot

Description

Create a raster ggplot with a wrapper around ggplot2::ggplot() + geom_raster().

Usage

gg_raster(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

faithfuld |>
  gg_raster(
    x = waiting,
    y = eruptions,
    col = density,
  )

Rect ggplot

Description

Create a rect ggplot with a wrapper around ggplot2::ggplot() + geom_rect().

Usage

gg_rect(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

data.frame(
  x = rep(c(2, 5, 7, 9, 12), 2),
  y = rep(c(1, 2), each = 5),
  z = factor(c(rep(1:4, each = 2), 5, NA)),
  w = rep(diff(c(0, 4, 6, 8, 10, 14)), 2)
) |>
  mutate(
    xmin = x - w / 2,
    xmax = x + w / 2,
    ymin = y,
    ymax = y + 1
  ) |>
  gg_rect(
    xmin = xmin,
    xmax = xmax,
    ymin = ymin,
    ymax = ymax,
    col = z,
  )

Ribbon ggplot

Description

Create a ribbon ggplot with a wrapper around ggplot2::ggplot() + geom_ribbon()

Usage

gg_ribbon(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

data.frame(year = 1875:1972, level = as.vector(LakeHuron)) |>
  mutate(level_min = level - 1, level_max = level + 1) |>
  gg_ribbon(
    x = year,
    ymin = level_min,
    ymax = level_max,
    x_labels = \(x) x,
    y_label = "Level",
  ) +
  geom_line(mapping = aes(y = level))

Rug ggplot

Description

Create a rug ggplot with a wrapper around ggplot2::ggplot() + geom_rug().

Usage

gg_rug(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_rug(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
  )

Segment ggplot

Description

Create a segment ggplot with a wrapper around ggplot2::ggplot() + geom_segment().

Usage

gg_segment(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

data.frame(x1 = 2.62, x2 = 3.57, y1 = 21.0, y2 = 15.0) |>
  gg_segment(
    x = x1,
    xend = x2,
    y = y1,
    yend = y2,
  )

Sf ggplot

Description

Create a blank ggplot with a wrapper around ggplot2::ggplot() + geom_sf().

Usage

gg_sf(
  data = NULL,
  ...,
  stat = "sf",
  position = "identity",
  coord = ggplot2::coord_sf(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

if (requireNamespace("sf", quietly = TRUE)) {
  sf::st_read(system.file("shape/nc.shp", package = "sf")) |>
    gg_sf(
      col = AREA,
    )
}

Smooth ggplot

Description

Create a smooth ggplot with a wrapper around ggplot2::ggplot() + geom_smooth().

Usage

gg_smooth(
  data = NULL,
  ...,
  stat = "smooth",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  gg_smooth(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
  )

Step ggplot

Description

Create a step plot with a wrapper around ggplot2::ggplot() + geom_step().

Usage

gg_step(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

economics |>
  filter(date > lubridate::ymd("2010-01-01")) |>
  gg_step(
    x = date,
    y = unemploy,
    y_expand_limits = 0,
    y_label = "Unemployment",
  )

Text ggplot

Description

Create a text plot with a wrapper around ggplot2::ggplot() + geom_text().

Usage

gg_text(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)

set_blanket()

bind_rows(
  mtcars |> slice_min(order_by = mpg),
  mtcars |> slice_max(order_by = mpg)
) |>
  tibble::rownames_to_column("model") |>
  gg_text(
    x = model,
    y = mpg,
    col = mpg,
    label = model,
    y_expand_limits = 0,
    y_label = "Miles per gallon",
    col_palette = c(orange, "white", teal),
  )

Tile ggplot

Description

Create a tile plot with a wrapper around ggplot2::ggplot() + geom_tile().

Usage

gg_tile(
  data = NULL,
  ...,
  stat = "identity",
  position = "identity",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  group_by(species, sex) |>
  summarise(across(flipper_length_mm, \(x) mean(x, na.rm = TRUE))) |>
  gg_tile(
    x = sex,
    y = species,
    col = flipper_length_mm,
  )

Violin ggplot

Description

Create a violin plot with a wrapper around ggplot2::ggplot() + geom_violin().

Usage

gg_violin(
  data = NULL,
  ...,
  stat = "ydensity",
  position = "dodge",
  coord = ggplot2::coord_cartesian(clip = "off"),
  mode = NULL,
  mode_orientation = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  xend = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  yend = NULL,
  z = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  subgroup = NULL,
  label = NULL,
  text = NULL,
  sample = NULL,
  mapping = NULL,
  x_breaks = NULL,
  x_breaks_n = NULL,
  x_expand = NULL,
  x_expand_limits = NULL,
  x_label = NULL,
  x_labels = NULL,
  x_position = "bottom",
  x_sec_axis = ggplot2::waiver(),
  x_symmetric = NULL,
  x_transform = NULL,
  y_breaks = NULL,
  y_breaks_n = NULL,
  y_expand = NULL,
  y_expand_limits = NULL,
  y_label = NULL,
  y_labels = NULL,
  y_position = "left",
  y_sec_axis = ggplot2::waiver(),
  y_symmetric = NULL,
  y_transform = NULL,
  col_breaks = NULL,
  col_breaks_n = 5,
  col_drop = FALSE,
  col_expand_limits = NULL,
  col_label = NULL,
  col_labels = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_palette = NULL,
  col_palette_na = NULL,
  col_rescale = scales::rescale(),
  col_steps = FALSE,
  col_transform = NULL,
  facet_axes = NULL,
  facet_axis_labels = "margins",
  facet_drop = FALSE,
  facet_labels = NULL,
  facet_layout = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  label_to_case = snakecase::to_sentence_case
)

Arguments

data

A data frame or tibble.

...

Other arguments passed to within a params list in layer().

stat

A statistical transformation to use on the data. A snakecase character string of a ggproto Stat subclass object minus the Stat prefix (e.g. "identity").

position

A position adjustment. A snakecase character string of a ggproto Position subclass object minus the Position prefix (e.g. "identity"), or a ⁠position_*()⁠ function that outputs a ggproto Position subclass object (e.g. ggplot2::position_identity()).

coord

A coordinate system. A ⁠coord_*()⁠ function that outputs a constructed ggproto Coord subclass object (e.g. ggplot2::coord_cartesian()).

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

mode_orientation

The orientation of plot, which affects the theme components that are removed from the mode. Either "x" or "y".

x, xmin, xmax, xend, y, ymin, ymax, yend, z, col, facet, facet2, group, subgroup, label, text, sample

An unquoted aesthetic variable.

mapping

A set of additional aesthetic mappings in ggplot2::aes(). Intended primarily for non-supported aesthetics (e.g. shape, linetype, linewidth, or size), but can also be used for delayed evaluation etc.

x_breaks, y_breaks, col_breaks

A ⁠scales::breaks_*⁠ function (e.g. ⁠scales::breaks_*()⁠), or a vector of breaks.

x_breaks_n, y_breaks_n, col_breaks_n

A number of desired breaks for when ⁠*_breaks = NULL⁠.

x_expand, y_expand

Padding to the limits with the ggplot2::expansion() function, or a vector of length 2 (e.g. c(0, 0)).

x_expand_limits, y_expand_limits, col_expand_limits

For a continuous variable, any values that the limits should encompass (e.g. 0). For a discrete scale, manipulate the data instead with forcats::fct_expand.

x_label, y_label, col_label

Label for the axis or legend title. Use + ggplot2::labs(... = NULL) for no title.

x_labels, y_labels, col_labels, facet_labels

A function that takes the breaks as inputs (e.g. ⁠\(x) stringr::str_to_sentence(x)⁠ or ⁠scales::label_*()⁠), or a vector of labels. (Note this must be named for facet_labels).

x_position, y_position

The position of the axis (i.e. "left", "right", "bottom" or "top").If using y_position = "top" with a ⁠*_mode_*⁠ theme, add caption = "" or caption = "\n".

x_sec_axis, y_sec_axis

A secondary axis with ggplot2::dup_axis() or ggplot2::sec_axis().

x_symmetric, y_symmetric

TRUE or FALSE of whether a symmetric scale.

x_transform, y_transform, col_transform

For a continuous scale, a transformation object (e.g. scales::transform_log10()) or character string of this minus the transform_ prefix (e.g. "log10").

col_drop, facet_drop

For a discrete variable, FALSE or TRUE of whether to drop unused levels.

col_legend_ncol, col_legend_nrow

The number of columns and rows in a legend guide.

col_legend_rev

TRUE or FALSE of whether to reverse the elements of a legend guide. Defaults to FALSE.

col_palette

A character vector of hex codes (or names) or a ⁠scales::pal_*()⁠ function.

col_palette_na

A hex code (or name) for the colour of NA values.

col_rescale

For a continuous variable, a scales::rescale() function.

col_steps

For a continuous variable, TRUE or FALSE of whether to colour in steps. Defaults to FALSE.

facet_axes

Whether to add interior axes and ticks with "margins", "all", "all_x", or "all_y". Sometimes ⁠+ *_mode_*()⁠ may be needed.

facet_axis_labels

Whether to add interior axis labels with "margins", "all", "all_x", or "all_y".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

facet_ncol, facet_nrow

The number of columns and rows of facet panels. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

When the facet scales are not "fixed", whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

title

Title string.

subtitle

Subtitle string.

caption

Caption title string.

label_to_case

A function to format the default x_label, y_label and col_label of unlabelled variables. Defaults to snakecase::to_sentence_case.

Value

A ggplot object.

Examples

library(ggplot2)
library(dplyr)
library(palmerpenguins)

set_blanket()

penguins |>
  tidyr::drop_na(sex) |>
  gg_violin(
    x = species,
    y = body_mass_g,
    col = sex,
  )

A grey colour

Description

A grey colour.

Usage

grey

Value

A character vector.

Examples

scales::show_col(grey)

The jumble palette

Description

A discrete palette that is relatively colour-blind safe.

Usage

jumble

teal

orange

navy

red

pink

purple

Value

A character vector.

Examples

colorspace::swatchplot(c(jumble, grey), cvd = TRUE)

Label every nth element

Description

Label every nth element in a vector, and replace the rest with "".

Usage

label_every_nth(..., n = 2, offset = 0)

Arguments

...

If numeric, arguments passed to the scales::comma function. Otherwise, arguments passed to format.

n

The increment of elements to hold as is. Defaults to 2.

offset

An offset for which element to first hold. Defaults to 0. Possible values are -1 to (n - 2)

Value

A labelling function

Examples

label_every_nth()(scales::comma(seq(1000, 5000, 1000)))
 label_every_nth()(lubridate::ymd(c("2021-01-01", "2022-01-01", "2023-01-01", "2024-01-01")))
 label_every_nth()(LETTERS[1:12])

 library(dplyr)
 library(palmerpenguins)

 set_blanket()

 penguins |>
   mutate(across(sex, \(x) stringr::str_to_sentence(x))) |>
   gg_point(
     x = flipper_length_mm,
     y = body_mass_g,
     col = sex,
     x_labels = label_every_nth(),
     y_labels = label_every_nth(),
   )

Light mode theme family

Description

A dark mode family of functions:

  • light_mode_r() with legend on right

  • light_mode_t() with legend on top

  • light_mode_b() with legend on bottom

Usage

light_mode_r(
  ...,
  base_size = 11,
  base_family = "",
  base_colour = "#121B24FF",
  axis_line_colour = "#121B24FF",
  axis_line_linewidth = 0.33,
  axis_ticks_colour = axis_line_colour,
  axis_ticks_linewidth = axis_line_linewidth,
  panel_grid_colour = "#F6F8FAFF",
  panel_grid_linewidth = 1.33,
  panel_background_fill = "#FFFFFFFF",
  plot_background_fill = "#FFFFFFFF",
  legend_axis_line_colour = plot_background_fill,
  legend_axis_line_linewidth = 0.33,
  legend_background_fill = plot_background_fill,
  legend_key_fill = plot_background_fill,
  legend_ticks_colour = legend_axis_line_colour,
  legend_ticks_linewidth = legend_axis_line_linewidth,
  legend_ticks_length = ggplot2::rel(c(0.175, 0))
)

light_mode_t(
  ...,
  base_size = 11,
  base_family = "",
  base_colour = "#121B24FF",
  axis_line_colour = "#121B24FF",
  axis_line_linewidth = 0.33,
  axis_ticks_colour = axis_line_colour,
  axis_ticks_linewidth = axis_line_linewidth,
  panel_grid_colour = "#F6F8FAFF",
  panel_grid_linewidth = 1.33,
  panel_background_fill = "#FFFFFFFF",
  plot_background_fill = "#FFFFFFFF",
  legend_axis_line_colour = plot_background_fill,
  legend_axis_line_linewidth = 0.33,
  legend_background_fill = plot_background_fill,
  legend_key_fill = plot_background_fill,
  legend_ticks_colour = legend_axis_line_colour,
  legend_ticks_linewidth = legend_axis_line_linewidth,
  legend_ticks_length = ggplot2::rel(c(0.175, 0))
)

light_mode_b(
  ...,
  base_size = 11,
  base_family = "",
  base_colour = "#121B24FF",
  axis_line_colour = "#121B24FF",
  axis_line_linewidth = 0.33,
  axis_ticks_colour = axis_line_colour,
  axis_ticks_linewidth = axis_line_linewidth,
  panel_grid_colour = "#F6F8FAFF",
  panel_grid_linewidth = 1.33,
  panel_background_fill = "#FFFFFFFF",
  plot_background_fill = "#FFFFFFFF",
  legend_axis_line_colour = plot_background_fill,
  legend_axis_line_linewidth = 0.33,
  legend_background_fill = plot_background_fill,
  legend_key_fill = plot_background_fill,
  legend_ticks_colour = legend_axis_line_colour,
  legend_ticks_linewidth = legend_axis_line_linewidth,
  legend_ticks_length = ggplot2::rel(c(0.175, 0))
)

Arguments

...

Provided to force user argument naming etc.

base_size

The base size of the text theme element. Defaults to 11.

base_family

The base family of the text theme element. Defaults to "".

base_colour

The base colour of the text theme element.

axis_line_colour

The colour of the axis.line theme element.

axis_line_linewidth

The linewidth of the axis.line theme element.

axis_ticks_colour

The colour of the axis.ticks theme element.

axis_ticks_linewidth

The linewidth of the axis.ticks theme element.

panel_grid_colour

The colour of the panel.grid theme element.

panel_grid_linewidth

The linewidth of the panel.grid theme element.

panel_background_fill

The fill (and colour) of the panel.background theme element.

plot_background_fill

The fill (and colour) of the plot.background theme element.

legend_axis_line_colour

The colour of the legend.axis.line theme element.

legend_axis_line_linewidth

The linewidth of the legend.axis.line theme element.

legend_background_fill

The fill (and colour) of the legend.background theme element.

legend_key_fill

The fill (and colour) of the legend.key theme element.

legend_ticks_colour

The colour of the legend.ticks theme element.

legend_ticks_linewidth

The linewidth of the legend.ticks theme element.

legend_ticks_length

The legend.ticks.length theme element.

Value

A ggplot theme.

Examples

library(palmerpenguins)
library(ggplot2)

set_blanket()

penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
    mode = light_mode_r()
  )

penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
    mode = light_mode_t()
  )

penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = species,
    mode = light_mode_b()
  )

Mode colour and linewidth defaults

Description

lightness and darkness are vectors of 3 colours used in the ⁠*_mode_*⁠ themes for the for the text, axis.line (and axis.ticks), panel.grid, panel.background and plot.background etc.

linewidthness is a vector of 2 integers used in the ⁠*_mode_*⁠ themes for the linewidth of the axis.line (axis.ticks and legend.ticks) and panel.grid theme elements.

Usage

lightness

darkness

linewidthness

Value

A character vector.

Examples

scales::show_col(c(lightness, darkness), ncol = 3)

Orientate a mode used outside of a ⁠gg_*⁠ context

Description

Add theme components to a mode used outside of a ⁠gg_*⁠ context

  • mode_orientation_to_x() Orientate the plot to the x axis.

  • mode_orientation_to_y() Orientate the plot to the y axis.

Usage

mode_orientation_to_x()

mode_orientation_to_y()

Value

ggplot2 theme components.

Examples

library(ggplot2)
library(palmerpenguins)

penguins |>
  ggplot() +
  geom_point(aes(x = flipper_length_mm, y = body_mass_g)) +
  light_mode_r() +
  mode_orientation_to_x()


penguins |>
  ggplot() +
  geom_bar(aes(y = island)) +
  light_mode_r() +
  mode_orientation_to_y()

Set a style

Description

Weave the style by setting:

  1. the mode to be added with ⁠gg_*()⁠ side-effects

  2. the colour/fill geom default, and other defaults for text, reference line and curve geoms

  3. the col_palettes for discrete, continuous and ordinal colour/fill scales

  4. a theme to be added without ⁠gg_*()⁠ side-effects.

Alternatively, use the ⁠weave_*⁠ functions to only apply a subset of these. ggplot2::update_geom_defaults() can be used to further fine-tune geom defaults.

Usage

set_blanket(
  ...,
  mode = light_mode_r(),
  colour = "#357BA2FF",
  fill = colour,
  text_colour = "#121B24FF",
  text_size = 11/2.835052,
  text_family = "",
  reference_line_colour = "#121B24FF",
  reference_line_linewidth = 0.33,
  col_palette_d = jumble,
  col_palette_na_d = "#CDC5BFFF",
  col_palette_c = viridisLite::mako(n = 9, direction = -1),
  col_palette_na_c = "#988F88FF",
  col_palette_o = scales::pal_viridis(option = "G", direction = -1),
  col_palette_na_o = "#988F88FF",
  theme = light_mode_r() + mode_orientation_to_x()
)

Arguments

...

Provided to force user argument naming etc.

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates ⁠gg_*⁠ side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.

colour

A default hex colour for the colour of geoms (other than text or reference line geoms).

fill

A default hex colour for the fill of geoms (other than text or reference line geoms).

text_colour

A default hex colour for the colour (and fill) of the "text" and "label" geoms.

text_size

A default size for the "text" and "label" geoms.

text_family

A default family for the "text" and "label" geoms.

reference_line_colour

A default hex colour for the colour of the "hline", "vline", "abline" and "curve" geoms.

reference_line_linewidth

A default linewidth for the the "hline", "vline", "abline" and "curve" geoms.

col_palette_d

For a discrete scale, a character vector of hex codes.

col_palette_na_d

For a discrete scale, a hex code.

col_palette_c

For a continuous scale, a character vector of hex codes.

col_palette_na_c

For a continuous scale, a hex code.

col_palette_o

For an ordinal scale, a ⁠scales::pal_*()⁠ function.

col_palette_na_o

For an ordinal scale, a hex code.

theme

A ggplot2 theme that the ⁠gg_*⁠ function will add without side-effects if the mode is set/weaved to NULL (and also is applied to ggplot code outside of ggblanket).

Value

A globally set style.

Examples

library(ggplot2)
library(ggblanket)
library(palmerpenguins)

set_blanket(
  mode = dark_mode_r(),
  colour = "#E7298AFF",
  text_colour = darkness[1],
  reference_line_colour = darkness[1],
  col_palette_d = c("#1B9E77FF", "#D95F02FF", "#7570b3FF", "#E7298AFF",
                    "#66A61EFF", "#E6AB02FF", "#A6761DFF", "#666666FF"),
)

penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
  ) +
  geom_vline(xintercept = 200) +
  annotate("text", x = I(0.25), y = I(0.75), label = "Here")

penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = species,
  ) +
  geom_vline(xintercept = 200) +
  annotate("text", x = I(0.75), y = I(0.75), label = "Here")

Set a discrete colour and fill palettes

Description

Set a discrete colour and fill palettes

Usage

weave_col_palettes(
  col_palette_d = jumble,
  col_palette_c = viridisLite::mako(n = 9, direction = -1),
  col_palette_o = scales::pal_viridis(option = "G", direction = -1),
  col_palette_na_d = "#CDC5BFFF",
  col_palette_na_c = "#988F88FF",
  col_palette_na_o = "#988F88FF",
  ...
)

Arguments

col_palette_d

For a discrete scale, a character vector of hex codes. Use NULL for ggplot2 default.

col_palette_c

For a continuous scale, a character vector of hex codes. Use NULL for ggplot2 default.

col_palette_o

For an ordinal scale, a ⁠scales::pal_*()⁠ function. Use NULL for ggplot2 default.

col_palette_na_d

For a discrete scale, a hex code.

col_palette_na_c

For a continuous scale, a hex code.

col_palette_na_o

For an ordinal scale, a hex code.

...

Dots to support trailing commas etc.


Set a series of geom defaults

Description

Update the colour/fill geom default, and update other defaults for text and reference line geoms.

ggplot2::update_geom_defaults() can be used to further fine-tune geom defaults.

Usage

weave_geom_defaults(
  colour = "#357BA2FF",
  fill = colour,
  text_colour = "#121B24FF",
  text_size = 11/2.835052,
  text_family = "",
  reference_line_colour = "#121B24FF",
  reference_line_linewidth = 0.33
)

Arguments

colour

A default hex colour for the colour of geoms (other than text or reference line geoms).

fill

A default hex colour for the fill of geoms (other than text or reference line geoms).

text_colour

A default hex colour for the colour (and fill) of the "text" and "label" geoms.

text_size

A default size for the "text" and "label" geoms.

text_family

A default family for the "text" and "label" geoms.

reference_line_colour

A default hex colour for the colour of the "hline", "vline", "abline" and "curve" geoms.

reference_line_linewidth

A default linewidth for the the "hline", "vline", "abline" and "curve" geoms.


Set a mode

Description

Set a mode for the mode argument in ⁠gg_*⁠ functions.

Usage

weave_mode(mode = light_mode_r())

Arguments

mode

A ggplot2 theme (e.g. light_mode_t() or dark_mode_r()) that anticipates ⁠gg_*⁠ side-effects of removing relevant axis line/ticks and gridlines per the mode_orientation.


Set a theme (without side-effects)

Description

Set a theme to be +-ed on unmodified to ⁠gg_*⁠ functions. Note, the mode takes precedence, unless the set/weaved mode is mode = NULL.

Usage

weave_theme(theme = light_mode_r() + mode_orientation_to_x())

Arguments

theme

A ggplot2 theme that the ⁠gg_*⁠ function will add without side-effects if the mode is set/weaved to NULL (and also is applied to ggplot code outside of ggblanket).