Learn R Programming

ggblanket (version 1.2.0)

gg_errorbar: Errorbar ggplot.

Description

Create a errorbar plot with a wrapper around the ggplot2::geom_errorbar function.

Usage

gg_errorbar(
  data = NULL,
  x = NULL,
  xmin = NULL,
  xmax = NULL,
  y = NULL,
  ymin = NULL,
  ymax = NULL,
  col = NULL,
  facet = NULL,
  group = NULL,
  text = NULL,
  stat = "identity",
  position = "identity",
  pal = NULL,
  pal_na = "#7F7F7F",
  alpha = 1,
  width = 0.1,
  ...,
  titles = NULL,
  title = NULL,
  subtitle = NULL,
  coord = NULL,
  x_breaks = NULL,
  x_expand = NULL,
  x_include = NULL,
  x_labels = NULL,
  x_limits = NULL,
  x_oob = scales::oob_censor,
  x_title = NULL,
  x_trans = "identity",
  y_breaks = NULL,
  y_expand = NULL,
  y_include = NULL,
  y_labels = NULL,
  y_limits = NULL,
  y_oob = scales::oob_censor,
  y_title = NULL,
  y_trans = "identity",
  col_breaks = NULL,
  col_include = NULL,
  col_intervals = NULL,
  col_labels = NULL,
  col_legend_place = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_limits = NULL,
  col_title = NULL,
  facet_intervals = NULL,
  facet_labels = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  caption = NULL,
  theme = NULL
)

Value

A ggplot object.

Arguments

data

A data frame or tibble.

x

Unquoted x aesthetic variable.

xmin

Unquoted xmin aesthetic variable.

xmax

Unquoted xmax aesthetic variable.

y

Unquoted y aesthetic variable.

ymin

Unquoted ymin aesthetic variable.

ymax

Unquoted ymax aesthetic variable.

col

Unquoted col and fill aesthetic variable.

facet

Unquoted facet aesthetic variable.

group

Unquoted group aesthetic variable.

text

Unquoted text aesthetic variable, which can be used in combination with plotly::ggplotly(., tooltip = "text").

stat

Statistical transformation. A character string (e.g. "identity").

position

Position adjustment. Either a character string (e.g."identity"), or a function (e.g. ggplot2::position_identity()).

pal

Colours to use. A character vector of hex codes (or names).

pal_na

Colour to use for NA values. A character vector of a hex code (or name).

alpha

Opacity. A number between 0 and 1.

width

Width. A number 0 upwards.

...

Other arguments passed to the relevant ggplot2::geom_* function.

titles

A function to format the x, y and col titles, including in rlang lambda format. Defaults to snakecase::to_sentence_case.

title

Title string.

subtitle

Subtitle string.

coord

Coordinate system.

x_breaks

A function that takes the limits as input (e.g. scales::breaks_pretty()), or a vector of breaks.

x_expand

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

x_include

For a numeric or date variable, any values that the scale should include (e.g. 0).

x_labels

A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels.

x_limits

A vector of length 2 to determine the limits of the axis.

x_oob

A scales::oob_* function for how to deal with out-of-bounds values.

x_title

Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.

x_trans

For a numeric variable, a transformation object (e.g. "log10").

y_breaks

A function that takes the limits as input (e.g. scales::breaks_pretty()), or a vector of breaks.

y_expand

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

y_include

For a numeric or date variable, any values that the scale should include (e.g. 0).

y_labels

A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels.

y_limits

A vector of length 2 to determine the limits of the axis.

y_oob

A scales::oob_* function for how to deal with out-of-bounds values.

y_title

Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.

y_trans

For a numeric variable, a transformation object (e.g. "log10").

col_breaks

A function that takes the limits as input (e.g. scales::breaks_pretty()), or a vector of breaks.

col_include

For a numeric or date variable, any values that the scale should include (e.g. 0).

col_intervals

A function to cut or chop the numeric variable into intervals (e.g. ~ santoku::chop_mean_sd(.x, drop = FALSE)).

col_labels

A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels. Note this does not affect where col_intervals is not NULL.

col_legend_place

The place for the legend. "r" for right, "b" for bottom, "t" for top, or "l" for left.

col_legend_ncol

The number of columns for the legend elements.

col_legend_nrow

The number of rows for the legend elements.

col_limits

A vector to determine the limits of the axis.

col_title

Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.

facet_intervals

A function to cut or chop the numeric variable into intervals, including in rlang lambda format (e.g. ~ santoku::chop_mean_sd(.x, drop = FALSE)).

facet_labels

A function that takes the breaks as inputs (e.g. scales::label_comma()), or a named vector of labels (e.g. c(value = "label", ...)).

facet_ncol

The number of columns of facetted plots.

facet_nrow

The number of rows of facetted plots.

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".

caption

Caption title string.

theme

A ggplot2 theme.

Examples

Run this code
library(ggplot2)

df <- 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(df, x = trt, ymin = lower, ymax = upper, col = group)
gg_errorbar(df, y = trt, xmin = lower, xmax = upper, col = group)

gg_errorbar(df, x = trt, y = resp, ymin = lower, ymax = upper, col = group) +
  geom_line(aes(group = group)) +
  geom_point()

dodger <- position_dodge(width = 0.75)

gg_blank(df, x = trt, y = resp, ymin = lower, ymax = upper, col = group) +
  geom_col(position = dodger, width = 0.75) +
  geom_errorbar(aes(x = trt, ymin = lower, ymax = upper, group = group),
                inherit.aes = FALSE,
                position = dodger,
                width = 0.1)

Run the code above in your browser using DataLab