add_watermark: Add a watermark to a plot

View source: R/xtra_watermark.R

add_watermarkR Documentation

Add a watermark to a plot

Description

Overlays large, semi-transparent, rotated text across a ggplot or xpose_plot object (e.g. "DRAFT", "PRELIMINARY", "CONFIDENTIAL"). Calling it directly always adds a watermark (falling back to the built-in defaults below if nothing else is configured). It is also applied automatically by print.xpose_plot() and ggsave_xp() whenever a default_watermark is actually configured (see the auto_apply entry in set_xtras_options()) – unlike this function, that automatic trigger never invents an unconfigured watermark on its own.

label/colour/alpha/size/angle/fontface resolve with the same precedence as apply_default_labs(): (in increasing precedence) the xpose.xtras.default_watermark R option, xpdb-level defaults set via set_default_watermark() (when xpdb is supplied), then the argument itself when explicitly passed. Built-in fallbacks ("DRAFT", "grey50", 0.3, 24, 30, "bold") apply if a setting isn't resolved from any of those.

Usage

add_watermark(plot, label, colour, alpha, size, angle, fontface, xpdb = NULL)

Arguments

plot

<ggplot> or <xpose_plot> object

label

<character> Watermark text

colour

<character> Text colour, passed to grDevices::adjustcolor()

alpha

<numeric> Transparency of the watermark text, between 0 (invisible) and 1 (opaque)

size

<numeric> Font size in points

angle

<numeric> Rotation angle in degrees (counter-clockwise)

fontface

<character> Font face, passed to grid::gpar()

xpdb

<xpose_data> or <xp_xtras> object plot was built from, used to resolve xpdb-level defaults (see set_default_watermark())

Value

plot, with the watermark layer added

See Also

set_xtras_options() for the full list of ⁠xpose.xtras.*⁠ session options, and get_xtras_option() to check which tier (option/xpdb) is currently dominant for a given xpdb.

Examples

p <- xpose::dv_vs_ipred(xpose::xpdb_ex_pk)
add_watermark(p, label = "PRELIMINARY")

options(xpose.xtras.default_watermark = list(label = "CONFIDENTIAL", colour = "red"))
add_watermark(p)
options(xpose.xtras.default_watermark = NULL)

xpose.xtras documentation built on Sept. 1, 2026, 5:08 p.m.