Learn R Programming

⚠️There's a newer version (1.0.0) of this package.Take me there.

unikn

Enabling elements of the University of Konstanz’s corporate design in R.

The unikn package provides color functions — by defining dedicated colors and color palettes, and commands for changing, viewing, and using them — and styled text elements (e.g., for marking, underlining, or plotting colored titles). The pre-defined range of colors and text functions is based on the corporate design of the University of Konstanz (see this link for details), but can be adapted and extended for other institutions and purposes.

Background

Institutions devise corporate design (CD) manuals for creating and maintaining a consistent impression in presentations and publications. In 2014, the University of Konstanz introduced a highly recognizable corporate design. Its key component is the ubiquitous use of a Seeblau color and a corresponding color palette that blends various shades of Seeblau (in boxes, lines, and other graphical elements) with text (in black-and-white). (See the corporate design pages and the Corporate Design Manual (pdf) for details.)

The unikn package facilitates the use of corporate design elements for users of R. While this renders the correct use of default specifications simple and straightforward, we leave some flexibility for experienced users (e.g., for creating scientific visualizations).

The unikn package currently provides five types of objects and functions:

  1. Dedicated colors and color palettes;
  2. Functions for viewing, changing, and comparing color palettes (i.e., seecol() and usecol());
  3. Functions for creating new color palettes and for finding colors by their names (i.e., newpal() and grepal());
  4. Functions for plotting graphical objects (e.g., boxes and frames);
  5. Functions for plotting styled text elements (e.g., highlighting and underlining text).

Additional elements may be added as they become available. Please use responsibly!

Installation

The latest release of unikn is available from CRAN at https://CRAN.R-project.org/package=unikn:

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

The current development version can be installed from its GitHub repository at https://github.com/hneth/unikn/:

# install.packages('devtools')  # (if not installed yet)
devtools::install_github('hneth/unikn')
library('unikn')  # loads the package

Colors and color functions

A distinctive and recognizable color scheme is the most recognizable element of the University of Konstanz’s corporate design.

Basic color palettes

Basic color palettes are specified according to the Corporate Design Manual (pdf):

The default color palette pal_unikn combines:

  • 5 shades of pal_seeblau (reversed, i.e., from darker to lighter);
  • the base R color "white" (as the center color);
  • 4 shades of grey (pal_grau[1:4]);
  • the base R color "black" (as the last color).

This yields a diverging, symmetrical default color palette pal_unikn consisting of 11 colors:

# Default color palette: ----- 
# pal_unikn  # 11 default colors

# View color palette (by plotting it): ----- 
seecol(pal_unikn)
  • A shorter version consisting of 10 colors is provided as pal_unikn_web.

  • An alternative color palette with 10 more muted colors (intended for PowerPoint presentations) is provided as pal_unikn_ppt.

Evaluating seecol(pal = "unikn_basic") shows these three basic unikn color palettes.

All color palettes

Beyond the three variants of pal_unikn, the unikn package provides the following color palettes:

seecol("all")

Specifically, an Excel file called Colours for complex graphics defines 9 additional color palettes that are exported by unikn as the following named color palettes:

# Show 9 color gradient palettes:
seecol(pal = "grad_all")

For details, evaluate or apply seecol() on the following color palettes:

# 8 mono-tone palettes: ----- 
# Name:          Nr:           Tone:          
pal_seeblau      # 5 shades of seeblau
pal_peach        # 5           peach
pal_grau         # 5           grau
pal_petrol       # 5           petrol
pal_seegruen     # 5           seegruen 
pal_karpfenblau  # 5           karpfenblau
pal_pinky        # 5           pink
pal_Bordeaux     # 5           Bordeaux

# 1 signal (Ampel) palette: ----- 
pal_signal       # 3           signal/Ampel

Each color palette contains a preferred color.[1] All preferred colors are contained in a corresponding color palette pal_unikn_pref:

# Using preferred colors: ----- 
pal_unikn_pref             # color palette of preferred colors
pal_unikn_pref[1]          # preferred (named) color 1
pal_unikn_pref[[1]]        # color value 1: #59C7EB"
pal_unikn_pref["Seeblau"]  # preferred color by name

Additional pre-defined color palettes include:

# Plot additional color palettes: ----- 
seecol(pal_unikn_pref)   # palette of  9 preferred colors
seecol(pal_unikn_light)  # palette of  8 light colors (in 4 pairs)
seecol(pal_unikn_dark)   # palette of  8 dark colors (in 4 pairs)
seecol(pal_unikn_pair)   # palette of 16 paired colors (in 8 pairs)

More flexible and complex color palettes can be created by using the seecol() and usecol() functions.

Overview of color-related functions

Two main functions seecol() and usecol() provide a convenient interface for viewing and using color palettes.

Two additional functions newpal() and grepal() serve in auxiliary roles (by allowing to create new color palettes and finding colors whose names match some pattern).

Viewing color palettes with seecol()

The seecol() function enables a quick inspection of a color palette. It provides a quick overview over the details of a color palette and allows comparisons between multiple color palettes:

# Plot a color palette: ----- 
seecol(pal = pal_unikn_pref,            # palette to plot
       col_brd = "white", lwd_brd = 5)  # color and width of borders

Partial color palettes

When only a subset of a color palette are needed, the seecol() and usecol() functions provide a reasonable subset of a known unikn color palette:

# All color palettes: ----- 
seecol(n = 4)
# Only pal_seeblau: ----- 
# seecol(pal_seeblau, n = 4)

Changing and creating color palettes

The usecol and seecol functions provide some generic options for manipulating and showing color gradients based on given colors or color palettes. This serves 2 main functions:

  1. Reducing or extending existing color palettes (to arbitrary lengths).
  2. Mixing and merging colors and color palettes into new color palettes.

Here are some examples of these functions in action:

  • Extending or reducing an existing color palette:
seecol(pal_unikn, n = 21)  
# seecol(pal_seeblau, n = 8)  # provides a subset of "good" colors

Note that reducing an unikn color palette selects a suitable subset of its colors, rather than just truncating the scale.

  • Mixing and merging colors and color palettes into new color palettes:
# Combining color palettes (and colors): ----- 
seecol(c(rev(pal_petrol),  "white", pal_bordeaux), 11,
       col_bg = "grey90")
# Related combinations:
seecol(c(rev(pal_seeblau), "white", pal_pinky), 11)
seecol(c(rev(pal_seeblau), "white", pal_seegruen), 11)
seecol(c(rev(pal_seeblau), "white", pal_peach), 11)

Using color palettes with usecol()

The unikn package exports the color palettes shown by seecol(pal = "all") and the nine preferred colors of pal_unikn_pref (e.g., Seeblau, Seegruen, etc.) as named colors.

The usecol() function provides convenient access and additional options for using them in graphs. Here are some examples:

  1. Using unikn color palettes and functions in base R plots:

By default, simply set the color argument of a plot to usecol() with some unikn color palette:

# (a) Using a color palette:
barplot(1/sqrt(1:11),  col = usecol(pal_unikn))

Two additional arguments allow modifying the existing color palette:

  • providing a value for n reduces or extends the selected color palette;

  • adding an opacity value for alpha (in the range [0, 1]) regulates color transparency.

  1. Visualizing unikn color palettes (using image() from graphics):
# Random images:
set.seed(1)
n <- 20
m <- matrix(rnorm(n*n), ncol = n, nrow = n)

# image(m, col = seecol(pal_seeblau))  # seecol() shows & use colors 
# image(m, col = usecol(pal_peach))    # usecol() only uses colors
# image(m, col = usecol(pal_seegruen))
# image(m, col = usecol(pal_petrol))
image(m, col = usecol(pal_seeblau, n = 50), 
      main = "50 shades of Seeblau", axes = FALSE)
  1. Using unikn in ggplot() commands (using ggplot2):
# 0. Create data: ---- 
# Example based on https://www.r-graph-gallery.com/137-spring-shapes-data-art/
n <- 50
names <- paste("G_", seq(1, n), sep = "")
df <- data.frame()

set.seed(3)
for(i in seq(1:30)){
    data = data.frame(matrix(0, n, 3))
    data[, 1] <- i
    data[, 2] <- sample(names, nrow(data))
    data[, 3] <- prop.table(sample( c(rep(0, 100), c(1:n)), nrow(data)))
    df = rbind(df, data)}
colnames(df) <- c("X","group","Y")
df <- df[order(df$X, df$group) , ]

# 1. Choose colors: ---- 

# (a) using RColorBrewer: 
library(RColorBrewer)
cur_col <- brewer.pal(11, "Paired") 
cur_col <- colorRampPalette(cur_col)(n)
cur_col <- cur_col[sample(c(1:length(cur_col)), size = length(cur_col))]  # randomize

# (b) using unikn:
library(unikn)
cur_col <- usecol(pal = pal_unikn, n = n)
# cur_col <- cur_col[sample(c(1:length(cur_col)), size = length(cur_col))]  # randomize

# 2. Plotting: ---- 
library(ggplot2)
ggplot(df, aes(x = X, y = Y, fill = group)) + 
  geom_area(alpha = 1, color = Grau, size = .01 ) +
  theme_bw() + 
  scale_fill_manual(values = cur_col) +
  theme_void() +
  theme(legend.position = "none")

Creating color palettes with newpal()

The newpal() function allows creating new color palettes (typically as data frames with dedicated color names).

The color palettes included in the unikn package are based on the CD manual of the University of Konstanz, Germany. However, the functionality provided by the package makes it easy and straightforward to define and use your own color scales. In the following, we provide examples to illustrate how this can be achieved for other corporations or institutions.

The colors of Princeton University

The color scheme of Princeton University is easily recognized by its combination of orange with black and white elements. The official guidelines (available here) define “Princeton Orange” as Pantone (PMS) 158 C.

  • The PANTONE™ color finder at https://www.pantone.com/color-finder/158-C yields the following color values:

    • RGB: 232 119 34
    • HEX/HTML: #E87722
    • CMYK: 0 62 95 0
  • However, the guide also specifies and distinguishes between two additional versions of orange and provides the following HEX/HTML values for them:

    • Orange on white: “#E77500”
    • Orange on black: “#F58025”

These definitions suggest defining three separate versions of orange and corresponding color palettes:

# HEX values for 3 shades of orange: 
orange_basic <- "#E87722"  # Pantone 158 C
orange_white <- "#E77500"  # orange on white
orange_black <- "#F58025"  # orange on black

# Defining color palettes:
pal_princeton <- c(orange_basic, "black")
names(pal_princeton) <- c("orange", "black")

pal_princeton_1 <- c(orange_white, "white", "black")
names(pal_princeton_1) <- c("orange_w", "white", "black")

pal_princeton_2 <- c(pal = c(orange_black, "black", "white"))
names(pal_princeton_2) <- c("orange_b", "black", "white")

Alternatively, we can define both (colors and names) in 1 step by using the newpal() function:

pal_princeton_1 <- newpal(col = c("#E77500", "white", "black"),
                          names = c("orange_w", "white", "black")
                          )
# seecol(pal_princeton_1)

The new color palettes (e.g., pal_princeton_1) can now be viewed with seecol(), scaled by usecol(), and used in graphs (e.g., in ggplot commands):

# View color palette: 
# seecol(pal_princeton_1)  

# Scale color palette (using df and n from above):
my_pal <- usecol(pal = pal_princeton_1, n = n)

# Use my_pal for plotting: 
ggplot(df, aes(x = X, y = Y, fill = group)) + 
  geom_area(alpha = 1, color = Grau, size = .01 ) +
  theme_bw() + 
  scale_fill_manual(values = my_pal) +
  theme_void() +
  theme(legend.position = "none")

The colors of Google

Color palettes for other entities and purposes can easily be created. To illustrate the steps involved, let’s create a color palette of the well-known Google logo.

The typical steps of creating a new palette are:

  1. Choose some colors (and their R color names, or as RGB/HEX/HCL values, e.g., from sites like https://www.schemecolor.com).

  2. Define the colors as an R vector (of type character).

  3. Define their names as a second R vector (of type character).

  4. Use the newpal() command to define the new color palette.

  5. Use the seepal() command to inspect the new color palette.

# 1. Choose colors:
# Google logo colors (from <https://www.schemecolor.com/google-logo-colors.php>)

# 2. Define colors (as vector):
color_google <- c("#4285f4", "#34a853", "#fbbc05", "#ea4335")

# 3. Define color names (as vector):
names_google <- c("blueberry", "sea green", "selective yellow", "cinnabar")

# 4. Define color palette:
pal_google <- newpal(color_google, names_google)

# 5. Inspect color palette:
seecol(pal_google, 
       col_brd = "white", lwd_brd = 8,
       title = "Colors of the Google logo")

The new palette pal_google can now be used in R graphics and modified in various ways (e.g., by the usecol() function).

See the vignette on “Institutional colors” of the unikn package for additional examples.

Finding colors with grepal()

The grepal() function allows finding colors in a color palettes by matching their name to a pattern.

Specifically, grepal(pattern, x) searches a color palette x (i.e., a vector of color names or data frame of named colors) for elements that match a pattern and returns those elements (colors) that match the pattern. The pattern can be a regular expression.

By default, grepal() searches the 657 named colors provided by colors() in base R:

# Find colors matching a pattern: 
oranges <- grepal("orange")

# See color palette:
seecol(oranges, 
       col_brd = "white", lwd_brd = 2, 
       title = "Shades of 'orange' in colors()")

Providing a list of color palettes to the pal argument of the seecol() function allows comparing multiple color palettes:

# Find colors:
pink_olive <- grepal("(pink)|(olive)")
purple_orange <- grepal("(purple)|(orange)")

# See color palettes:
seecol(pal = list(pink_olive, purple_orange), 
       pal_names = c("pink|olive", "purple|orange"), 
       title = "Comparing pink olives and purple oranges")

To make grepal() more powerful, its pattern argument can use regular expressions, and its x argument works with both vectors and data frames (e.g., the unikn color palettes).

Text decorations

Beyond color functions, unikn also provides some functions for plotting graphical elements (like boxes) and styled text (with decorations like colored backgrounds or underlining). By default, the text-decoration functions assume that you want to add styled text to an existing plot, unless the new_plot argument specifies a type of plot to be generated. As the use of these functions is explained in detail in vignette("Text"), we only provide some examples here:

Mark

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

mark(labels = c("Markieren", "ist ein Bestandteil", "von Studieren."), 
     x = 0, y = .8, y_layout = .03, cex = 1.5, new_plot = "slide")

Underline

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

uline(labels = c("Geradlinig", "Authentisch", "Beweglich", "Offen", "Paradiesisch"), 
      x = .05, y = .9, y_layout = "even", cex = 1.1, font = 2, new_plot = "slide")

Post

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

xbox(col = usecol(pal_seeblau[[5]]), dim = c(2, 2))
post(labels = c("Für eine", "Kultur der", "Kreativität"), x = .1, y = .8, cex = 1.4, font = 2)

The color and font parameters can be adjusted to obtain different looks:

post(labels = c("creative.", "together"), new_plot = "xbox", 
     y_layout = .02, cex = 2, font = c(1, 3),  
     col_bg = pal_seegruen[[1]], col = c(Petrol, Pinky))

Headings

The heading() function is a convenient wrapper around mark:

heading(labels = c("pa-", "ra-", "die-", "sisch"))

Headings violating the official recommendations (e.g., step-wise titles) will generate a message:

heading(labels = c("Ewig", "währt am", "längsten..."), 
        y = 2/3, col_bg = usecol(pal_pinky))
#> Step-wise titles are discouraged: Consider re-arranging?

URLs

Finally, the url_unikn() function allows formatting URLs the uni.kn way:

my_url <- url_unikn("https://www.uni-konstanz.de/")  # input URL as copied from web browser

post(labels = my_url, x = .2, y = .1, font = 4, new_plot = "xbox")

Using custom color palettes

If custom color palettes are available, the text decoration functions can be used for graphical annotations.

  • For instance, using color palettes of other academic institutions (defined in the vignette on “Institutional colors”):
  • Using the color palette pal_google (defined above):

Caveats

Please note the following caveats:

  • Plotting text (i.e., graphically rendering characters) is rarely a good idea. It typically doesn’t scale (when changing the size of images) and cannot be recognized automatically (e.g., copied, indexed, or scraped). Hence, the following functions should only be used in contexts in which no better solutions are available or practical (e.g., when specifically creating images, or needing to add text to graphs).

  • Like all other templates, our renderings are subject to constraints and limitations. As a standard installation of R lacks the official “Theinhardt” fonts, we can only mimic the design specifications (in Arial, sans serif). Nevertheless, the unikn package helps preventing common mistakes by novices (e.g., boxes or lines extending beyond text, or step-functions in multi-line titles) and can be customized and improved by expert users.

Overall, we hope that the following functions will be useful for plotting graphical elements (e.g., boxes, logos, etc.) and achieving a uniform look when styling visualizations.

ToDo

The unikn package is work in progress. We are still working on:

  • Graphical themes for ggplot2 that use unikn color palettes and text elements
  • Additional templates for images and slides

Please contact us in case you need additional features or want to help us implementing them.

Resources

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

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

Contact

Please report any unikn-related issues at https://github.com/hneth/unikn/issues. We appreciate your feedback, comments, or questions.

Copyrights

The University of Konstanz’s Corporate Design (CD) was created by Strichpunkt GmbH and the University of Konstanz in 2014. The unikn package authors belong to the research group on Social Psychology and Decision Sciences (SPDS) at the University of Konstanz. We make some CD elements available to fellow users of R (e.g., for creating scientific visualizations), but all copyrights remain with the original copyright holders.

We aim for an authentic representation of a highly-specified corporate design. While rigid specifications help to maintain coherence and consistency, they also tend to cause frustration in expert users. As the design has been developed in a flexible way that allows for individual elements to be modified as needed, we allow for some liberties, mostly by relaxing some restrictions. Examples include:

  • enabling finer color gradients and arbitrary combinations of color palettes (by applying the seecol() and usecol() functions to color palettes);
  • providing a designated Signal color (from pal_signal);
  • using the spelling “color” (rather than “colour”) throughout the unikn package.

License

unikn by Hansjörg Neth and Nico Gradwohl is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. (Based on a work at https://github.com/hneth/unikn).

References

The copyrights to all designs remain with their original creators:

Color definitions are based on the specifications at:

(Updated on 2021-03-24.)

[1] Whereas the official definition does not identify a preferred color for the Ampel color palette (pal_signal), we provide its alert color (i.e., pal_signal[2]) as a designated color Signal.

Copy Link

Version

Install

install.packages('unikn')

Monthly Downloads

528

Version

0.4.0

License

CC BY-SA 4.0

Maintainer

Hansjoerg Neth

Last Published

March 27th, 2021

Functions in unikn (0.4.0)

Peach

uni.kn color Peach.
Seegruen

uni.kn color Seegruen.
Grau

uni.kn color Grau.
grepal

Get a vector of colors whose names match a regular expression.
Seeblau

uni.kn color Seeblau.
Karpfenblau

uni.kn color Karpfenblau.
Petrol

uni.kn color Petrol.
Signal

uni.kn color Signal or alert.
Bordeaux

uni.kn color Bordeaux.
heading

Plot a heading (as marked text elements).
pal_grau

uni.kn grau color palette.
mark

Plot marked (or highlighted) text elements.
pal_karpfenblau

uni.kn karpfenblau color palette.
pal_unikn_light

uni.kn light colors in a color palette.
newpal

Define new color palettes.
pal_seegruen

uni.kn seegruen color palette.
unikn.guide

Opens the unikn package guides
uline

Plot underlined text elements.
pal_signal

uni.kn signal (Ampel) color palette.
pal_pinky

uni.kn pinky color palette.
Pinky

uni.kn color Pinky.
pal_seeblau

uni.kn seeblau color palette.
pal_unikn_web

uni.kn default color palette.
pal_peach

uni.kn peach color palette.
post

Post text (in an xbox).
pal_petrol

uni.kn petrol color palette.
pal_unikn_ppt

uni.kn secondary color palette (ppt version).
pal_unikn_pref

uni.kn preferred colors in a color palette.
pal_unikn

unikn default color palette (11 colors).
pal_bordeaux

uni.kn bordeaux color palette.
url_unikn

url_unikn formats an URL the uni.kn way.
usecol

Use a color or color palette.
pal_unikn_dark

uni.kn dark colors in a color palette.
seecol

Plot color palettes (to see their colors).
slide

Plot a slide (or frame).
pal_unikn_pair

uni.kn pairwise colors in a color palette.
xbox

Plot a box (with x).
theme_unikn

Basic unikn theme for ggplot2.
theme_grau

Alternative theme for ggplot2.