Skip to contents

Writes a small text annotation in the bottom-right corner of the current graphics device using grid. Call this after printing or displaying the plot. For publication-ready figures, omit the call; the plot is unchanged.

Usage

make_footnote(
  text = getwd(),
  timestamp = TRUE,
  prefix = "DRAFT — ",
  size = 0.7,
  colour = gray(0.5),
  x = 1,
  y = 0,
  hjust = "right",
  vjust = "bottom",
  margin_mm = 2,
  color = colour
)

makeFootnote(
  footnoteText = getwd(),
  size = 0.7,
  color = gray(0.5),
  timestamp = TRUE
)

Arguments

text

Text to display. Defaults to the current working directory; for most uses pass the script filename instead: make_footnote("R/analysis.R").

timestamp

Logical; if TRUE, Sys.time() is appended to text. Default TRUE. Set to FALSE for reproducible output.

prefix

String prepended to text before the timestamp. Default "DRAFT \u2014 ". Set to "" to suppress the prefix.

size

Font size as a multiplier relative to the device default (passed to grid::gpar() as cex). Default 0.7.

colour

The same as color: an alias kept for existing code. Give one or the other; both with different values is an error.

x

Horizontal position in normalized parent coordinates ("npc"). Default 1 (right edge). Decrease to move left.

y

Vertical position in "npc". Default 0 (bottom). Increase to move up.

hjust

Horizontal justification: "right" (default), "left", or "center".

vjust

Vertical justification: "bottom" (default), "top", or "center".

margin_mm

Margin in mm pulled back from the x/y position. Default 2.

color

Font color. Default gray(0.5) (medium gray), which is visually unobtrusive on both screen and print.

footnoteText

Equivalent to text in make_footnote().

Value

Called for its side effect (draws text on the current device). Returns invisible(NULL).

Details

Typical workflow:

# During analysis (draft)
p <- plot(hv_hazard(...)) + theme_hv_manuscript()
print(p)
make_footnote("analysis/mortality.R")   # adds draft annotation

# For publication — just don't call make_footnote()
ggsave("figures/fig1.pdf", p, width = 11, height = 8.5)

Examples

# --- Basic use after a base-R plot ----------------------------------------
plot(1:10, main = "Example")
make_footnote("examples/basic.R")


# --- With a ggplot2 figure and manuscript theme ---------------------------
# \donttest{
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title = "Motor Trend Cars") +
  theme_hv_manuscript()

# Draft: print, then annotate
print(p)
make_footnote("R/exploratory.R")


# Publication: save without footnote
ggsave(file.path(tempdir(), "fig1.pdf"), p, width = 11, height = 8.5)
# }

# --- Custom position and no timestamp ------------------------------------
plot(1:10)
make_footnote("Preliminary results", timestamp = FALSE, prefix = "")


# --- Suppress the DRAFT prefix -------------------------------------------
plot(1:10)
make_footnote(
  text      = paste("Analyst: J. Ehrlinger |", Sys.Date()),
  timestamp = FALSE,
  prefix    = ""
)