Skip to contents

When set_theme(quiet_labels = TRUE) is active (the default), geom_text() and geom_label() from ggastrum dispatch to ggrepel's repel geoms with themed defaults. This means labels automatically repel and hide overlapping ones.

Usage

geom_text(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  parse = FALSE,
  ...,
  quiet = TRUE,
  max.overlaps = .QUIET_MAX_OVERLAPS,
  min.segment.length = .QUIET_MIN_SEGMENT,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

geom_label(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  parse = FALSE,
  ...,
  quiet = TRUE,
  max.overlaps = .QUIET_MAX_OVERLAPS,
  min.segment.length = .QUIET_MIN_SEGMENT,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, stat, position, ...

Same as geom_text / geom_label.

parse

Logical. If TRUE, labels are parsed as expressions.

quiet

Logical. If TRUE (default), use ggrepel with themed quiet-label defaults. If FALSE, fall back to plain ggplot2 geom_text() / geom_label().

max.overlaps

Integer. Only used when quiet = TRUE. Labels that would overlap more than this many others are removed. Default 8.

min.segment.length

Numeric. Only used when quiet = TRUE. Segments shorter than this are hidden. Default 0.25.

na.rm

Logical. If TRUE, missing values are silently removed.

show.legend

Logical. Whether to include this layer in the legend.

inherit.aes

Logical. Whether to inherit aesthetics from the plot.

Value

A ggplot2 layer object.

Details

Set quiet = FALSE to use plain ggplot2 geom_text() / geom_label() for a single layer. Use reset_label_defaults() to restore ggplot2's original defaults globally.

Note: Internal ggplot2 uses of geom_text (e.g. stat_summary(geom = "text")) resolve through ggplot2's own registry and are unaffected by this override. To get quiet labels in stat layers, use geom = "qlabel" or geom = "qlabel_box".

Examples

if (FALSE) { # \dontrun{
library(ggplot2)
ggastrum::set_theme()

# geom_text() automatically uses ggrepel with themed defaults:
ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
  geom_point() +
  geom_text()

# Opt out for a single layer:
ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
  geom_point() +
  geom_text(quiet = FALSE)
} # }