ggplot_add_arrow: Add arrows to ggplot

View source: R/utility_plotgeometry.R

ggplot_add_arrowR Documentation

Add arrows to ggplot

Description

Add some arrow objects and annotation to an existing ggplot

Usage

ggplot_add_arrow(
  plt,
  x,
  y,
  theta = -pi/2,
  scale = 0.1,
  length = NULL,
  label = NULL,
  label_size = 3.5,
  label_parse = FALSE,
  label_offset = 0.02,
  linewidth = 0.5,
  colour = "black",
  scale_arrow = 0.3,
  scale_arrow_max = 0.1
)

Arguments

plt

existing ggplot object

x, y

x,y positions of arrow tips

theta

orientation of arrows (in rad)

scale

arrow length, in fraction of y-range

length

arrow length in x,y coordinate system. If specified, overrides 'scale' setting

label

labels for each arrow (string). Labels are plotted near the tail of each arrow

label_size

label text size

label_parse

if 'TRUE', parse the label input

label_offset

small offset to create distance between arrow tails. Expressed in fraction of y-range

linewidth

arrow line width

colour

arrow colour

scale_arrow

length of arrow head, as fraction of arrow length

scale_arrow_max

maximum arrow head size, as fraction of y-range

Examples

#generate a plot
plt <- ggplot2::ggplot() +
  ggplot2::geom_rect(ggplot2::aes(xmin = 0, xmax = 2, ymin = 0, ymax = 2), fill = "yellow") +
  ggplot2::coord_fixed(ratio = 1)

#arrow
x = c(1, 1, 1, 1)
y = c(1, 1, 1, 1)
theta = c(-pi/2, 0, pi/2, pi)
label = "test*theta"
ggplot_add_arrow(plt, x, y, theta = theta, label = label, label_parse = TRUE)

GJMeijer/soilmech documentation built on May 22, 2022, 10:39 a.m.