Text boxes and decorations

SPDS, uni.kn

2020 12 18


This vignette explains the unikn functions for plotting graphical elements and text decorations. (See the vignette on colors for general information on colors, color palettes, and corresponding functions, or the more specialized vignettes on color recipes and institutional colors.)

Please install and/or load the unikn package to get started:

# install.packages('unikn')  # install unikn from CRAN client
library('unikn')             # loads the package


Beyond providing support for colors, unikn provides functions for plotting graphical elements (like boxes) and text decorations (with colored backgrounds or underlining). Before illustrating these functions, please note some caveats:

That said, digital decorations can be useful to emphasize or structure information, provided that they can be produced easily and flexibly. The unikn package helps preventing common mistakes by novices (e.g., boxes or lines extending beyond text, or step-functions in multi-line headings) and can be customized and improved by expert users. Hence, we hope that the following functions are useful for plotting graphical elements (e.g., boxes, logos, etc.) and help you achieve a uniform look when styling presentations or visualizations.

Please load the unikn package to get started:

library(unikn)  # load unikn package

Plotting empty slides and boxes

As the text functions of unikn add styled text to an existing plot, we must first create a plot to which we can add text. unikn provides 2 basic functions for creating new plots:

  1. slide plots an empty canvass (a rectangular box or frame);
  2. xbox plots a colored box with an X in its top right corner.

Here are both commands with their default settings:

slide()  # plot default slide

xbox()  # plot default xbox

Both functions accept additional arguments to customize their appearance.


The background and border colors of slides can be changed by setting their col, border, and lwd arguments:

Similarly, the background color of xboxes can be changed by the col argument:


By default, both slide and xbox fill the entire plotting region (i.e., all margins are set to 0).

The width of a slide is set to 4/3 of its height (of 1). To change this default, use the dim argument for specifying the slide’s x- and y-dimensions, respectively:

Similarly, an xbox has the default dimensions of a unit square (i.e., dim = c(1, 1)). To change this default, use the dim argument for specifying the xbox’s x- and y-dimensions, respectively:

The 2 strokes of the X (in the top right corner) are orthogonal when viewing the xbox at the aspect ratio indicated by dim (i.e., here: at a ratio of width x = 1 to height y = 2). When viewing the box at any different aspect ratio, the X appears to be distorted. Hence, viewing and printing plots at the desired aspect ratio helps when creating an xbox.

Plotting styled text

There are 3 main functions for plotting text with decorations:

In addition, there are 2 auxiliary functions:

The following sections illustrate the functions and their main options in turn.

Mark text

The mark function allows highlighting text by plotting it with colored background boxes (to provide the functionality of “Markieren”):

By default, mark assumes that we want to add highlighted text to an already existing plot. The text labels to be added are provided (as a character vector) by the labels argument, their coordinates as the corresponding x and y arguments. Various text decorations (i.e., text and background colors, text sizes, and font types) can be set by specifying additional arguments (i.e., col, col_bg, cex, and font, respectively):

If no pre-existing plot is available, setting the new_plot argument to either "blank" or "slide" will generate a new default plot (by using the slide function described above):

Instead of providing explicit x and y coordinates for all text elements in labels, the calls above defined an initial coordinate and used a numeric y_layout argument to fix the distance between consecutive text labels (to a value of .03). Special values for y_layout are:

See ?mark for details.

Underline text

The uline function allows emphasizing text by plotting it with colored underlining (to provide the functionality of “Unterstreichen”):

As with mark above, the uline command distinguishes between creating a new plot (by setting new_plot to either "blank" or “slide”) or adding to a pre-existing plot (by using the default new_plot = "none"):

The arguments for text elements (labels), text positions (x, y, y_layout), and text properties and decorations (col, col_bg, cex, and font) work as they do for mark. For instance, shorter vectors are recycled to match the length of labels:

Post text

The post function allows adding text to a rectangular xbox (to provide the functionality of “Merken”):

By default, post assumes a pre-existing xbox to which the text elements of labels are to be added.
For square boxes, setting new_plot to "xbox" creates a new xbox with its default dimensions of dim = c(1, 1).
By adjusting its color and text arguments, post allows creating simple badges or logos:

Another potential use of post is for creating images providing contact details:


The heading function makes it easy to create recognizable headings:

By default, the function creates a new slide (i.e., new_plot = "slide") and positions the text elements of labels on its left edge (i.e., x = 0, y = .8 and y_layout = "flush"). Headings violating the recommendations (see p. 25 of the CD manual) will generate a message, for instance:

When colors are left unspecified, heading selects colors that are appropriate for the number of elements in labels (i.e., shades of Seeblau for col_bg = "default"). However, default colors can be overwritten by setting the col and col_bg arguments:


One of the more obscure rules (on p. 31 of the CD manual) concerns the rendering of URLs, in which typical web patterns (like “http” or “www”) are to be omitted and replaced by a typographical dash (which is longer than a hyphen). The url_unikn utility function allows formatting URLs the uni.kn way:


The following versions of unikn and corresponding resources are currently available:

Type: Version: URL:
A. unikn (R package): Release version https://CRAN.R-project.org/package=unikn
  Development version https://github.com/hneth/unikn/
B. Online documentation: Release version https://hneth.github.io/unikn/
  Development version https://hneth.github.io/unikn/dev/



The following vignettes provide instructions and examples for using the unikn colors, color palettes, and functions:

Nr. Vignette Content
1. Colors Colors and color functions
2. Color recipes Recipes for color-related tasks
3. Institutional colors Creating color palettes for other institutions
4. Text Text boxes and decorations