geom_abs_text: Text positioned relative to a ggplot panel/facet

geom_abs_textR Documentation

Text positioned relative to a ggplot panel/facet

Description

geom_abs_text functions similarly to ggplot2's geom_text, except that instead of taking x and y aesthetics, it requires xpos and ypos aesthetics, values from 0-1 that determine the absolute x and y coordinates with respect to whatever viewport they are being plotted in, be that the full panel or a facet panel. A value of 0.5 indicates the center of the axis, and a value of 1 indicates the far edge of the axis.

This code and its documentation is based off code in the ggplot2 package, and thus is subject to the copy-left licenses of the original package.

Usage

geom_abs_text(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  ...,
  parse = FALSE,
  inherit.aes = TRUE
)

geom_abs_label(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  ...,
  parse = FALSE,
  label.padding = unit(0.25, "lines"),
  label.r = unit(0.15, "lines"),
  label.size = 0.25,
  na.rm = FALSE,
  inherit.aes = TRUE
)

annotate_abs_text(xpos, ypos, ...)

annotate_abs_label(xpos, ypos, ...)

Arguments

mapping, data, ..., stat, parse, inherit.aes

See the documentation for ggplot2::geom_text()

...

Other arguments passed on to ggplot2::layer(). It must include an argument named label. Otherwise, these are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red".'

label.padding, label.r, label.size

See the documentation for ggplot2::geom_label()

xpos

A numeric between 0 and 1, indicating the x position

ypos

A numeric between 0 and 1, indicating the y position

Details

This function has only been tested in a few scenarios, and only in ggplot2 v2.2.1.

Examples

df <- data.frame(
  x = c(99, 0, 1),
  y = c(-100, 0, 100),
  label = c("A","B", "C")
)

ggplot(df, aes(x=x,y=y,label=label, color=label)) +
  geom_point() +
  geom_text() +
  facet_wrap(~label, scales="free") +
  geom_abs_text(aes(xpos=0.5, ypos=0.75, label = paste0("relative: ", label))) +
  annotate_abs_label(xpos=0.25, ypos=0.25, label="wildcard!")


burchill/zplyr documentation built on Feb. 2, 2023, 11:01 a.m.