Skip to contents

Sets a wordmark or a logo behind the table body, faint enough to read through.

Usage

gt_watermark(
  gt_object,
  text = NULL,
  image = NULL,
  opacity = 0.06,
  size = "60%",
  position = "center",
  color = "#000000",
  angle = 0,
  font = "Helvetica, Arial, sans-serif"
)

Arguments

gt_object

A gt table object to modify.

text

Optional. Text to render as the watermark. Defaults to NULL.

image

Optional. A path to a PNG, JPEG, or SVG file to use instead of text. Defaults to NULL.

opacity

Numeric. How faint the watermark is, from 0 to 1. Defaults to 0.06.

size

Character. The width of the watermark relative to the table, as a CSS background size such as "60%". Defaults to "60%".

position

Character. Where it sits, as a CSS background position such as "center" or "right bottom". Defaults to "center".

color

Character. The text color, used only with text. Defaults to "#000000".

angle

Numeric. Rotation in degrees, used only with text. Defaults to 0.

font

Character. The font family for text. Defaults to a system sans-serif.

Value

Returns a modified gt table with a watermark behind the body.

Details

A text watermark is drawn as an inline SVG rather than as HTML, because a background image is the only way to sit behind the table body without taking up a row. An SVG background cannot load the page's webfonts, so font has to name a face installed on the machine rendering the table.

The watermark sits behind the body cells, so it will be hidden wherever a cell has its own fill, from row striping or from gt::data_color().

See also

gt_social_tag() for visible attribution in the source note.

Examples

library(gt)

afc_south <- subset(
  sdv_example_standings, division == "AFC South",
  c(team_name, wins:points_against)
)

gt(afc_south) |> gt_watermark(text = "DRAFT", angle = -30, opacity = 0.08)
team_name wins losses ties win_pct points_for points_against
Jacksonville Jaguars 13 4 0 0.765 474 336
Houston Texans 12 5 0 0.706 404 295
Indianapolis Colts 8 9 0 0.471 466 412
Tennessee Titans 3 14 0 0.176 284 478
# any local png, jpeg, gif or svg; a small svg written on the spot here logo <- tempfile(fileext = ".svg") writeLines(paste0( '<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40">', '<circle cx="20" cy="20" r="18"/></svg>' ), logo) gt(afc_south) |> gt_watermark(image = logo, size = "40%", position = "right bottom")
team_name wins losses ties win_pct points_for points_against
Jacksonville Jaguars 13 4 0 0.765 474 336
Houston Texans 12 5 0 0.706 404 295
Indianapolis Colts 8 9 0 0.471 466 412
Tennessee Titans 3 14 0 0.176 284 478