ggsave_vbracket: Save a ggplot with vbracket legend

View source: R/ggsave_vbracket.R

ggsave_vbracketR Documentation

Save a ggplot with vbracket legend

Description

This function is a wrapper around ggsave() that properly handles vbracket legends. Use this instead of ggsave() when your plot has a legend_bracket().

Usage

ggsave_vbracket(
  filename,
  plot,
  device = NULL,
  width = NA,
  height = NA,
  units = c("in", "cm", "mm", "px"),
  dpi = 300,
  ...
)

Arguments

filename

File name to save plot to

plot

Plot to save (must have legend_bracket)

device

Device to use (default auto-detects from filename)

width

Width in units

height

Height in units

units

Units for width and height ("in", "cm", "mm", "px")

dpi

DPI for raster devices

...

Additional arguments passed to ggsave()

Value

No return value, called for its side effects. Saves the plot (including the vbracket legend, if present) to the file specified by filename.

Examples


library(ggplot2)
data <- data.frame(x = 1:10, y = 1:10, group = rep(c("A", "B"), each = 5))
labels <- c("A", "B")
colors <- c("A" = "red", "B" = "blue")
comparisons <- add_bracket_comparisons(groups1 = "A", groups2 = "B", labels = "*")

p <- ggplot(data, aes(x, y, color = group)) +
  geom_point() +
  legend_bracket(labels, colors, comparisons,
                 position = "topleft", output_width = 6, output_height = 4)

ggsave_vbracket(file.path(tempdir(), "plot.pdf"), p, width = 6, height = 4)


vbracket documentation built on Jan. 7, 2026, 9:06 a.m.