knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

This package provides some functions that make it easy to create figures in accordance with the corporate design colors of the Institute for Comprehensive Analysis of the Economy (ICAE) at the Johannes Kepler University in Linz.^[More information about the ICAE can be found here.] I am currently adding the color scheme for the official colors of the Europa University Flensburg as well.

The package is still under development. Here is just a quick overview over its functions. Note that all exported function already have a complete documentation so you might refer to the help function for more details.

For the following purposes, this example code and the packages dplyr as well as ggplot2 are used:

x <- seq(1,10, length.out=30)
y <- rep(1, length(x))
data <- data.frame(x=x, y=y)
palettes <- c("main", "cool", "hot", "mixed")
library(dplyr)
library(ggplot2)
library(icaeDesign)

The palettes

Currently, the package contains the following four palettes for the ICAE:

pal_plots <- list()
for (n in palettes){
  pal_name <- n
  pal_plots[[pal_name]] <- ggplot(data, 
                                  aes(x, y, z= x)
                                  ) + 
    geom_tile(aes(fill = x)) + 
  scale_fill_icae(pal_name, discrete = F) +
  ggtitle(paste0(pal_name)) +
  theme_void() + 
    theme(legend.position = "none", 
          plot.title = element_text(hjust = 0.5, size = 10))
  print(pal_plots[[pal_name]] )
}

There are four similar palettes for the EUF case:

pal_plots <- list()
for (n in palettes){
  pal_name <- n
  pal_plots[[pal_name]] <- ggplot(data, 
                                  aes(x, y, z= x)
                                  ) + 
    geom_tile(aes(fill = x)) + 
  scale_fill_euf(pal_name, discrete = F) +
  ggtitle(paste0(pal_name)) +
  theme_void() + 
    theme(legend.position = "none", 
          plot.title = element_text(hjust = 0.5, size = 10))
  print(pal_plots[[pal_name]] )
}

All of them come with both continuous and discrete versions.

Using the palettes

Create color vectors

To get a vector of arbitrary length that contains the hex codes for colors from the ICAE palettes introduced above, use the function get_icae_colors, which generates a vector of n different hex codes:

list_of_cols <- list(
  "hot_colors" = get_icae_colors(n = 3, palette_used = "hot"),
  "cold_colors" = get_icae_colors(n = 2, palette_used = "cool", 
                                  reverse_pal = TRUE),
  "mixed_colors" = get_icae_colors(4, palette_used = "mixed")
)
print(list_of_cols)

You may also inquire the hex codes for the colors that are part of the corporate design:

get_icae_colors(c("sand", "dark green"))

If you want to get the hex codes for all base colors of the corporate design call:

get_icae_colors("all")

Update ggplot2 objects

The key functions are scale_color_icae() and scale_fill_icae(), which allow to control the color and fill aesthetics in ggplot2 objects respectively.

In case of a barplot you might use scale_fill_icae() as follows:

data("iris")
iris %>%
  group_by(Species) %>%
  summarise_all(mean) %>%
  ungroup() %>%
  ggplot(.) + 
  geom_bar(
    aes(x=Species, y=Petal.Width, fill=Species), 
    stat = "identity"
    ) + 
  scale_fill_icae() + 
  theme_minimal()

Note that by default the functions return a discrete scale and for continuous cases you need to set discrete = FALSE explicitly.

iris %>%
  ggplot(.) + geom_point(
    aes(x=Sepal.Length, color=Sepal.Width, y=Petal.Length)
    ) +
  scale_color_icae(discrete = F) + 
  theme_minimal()

For distinguishing discrete categories via color, such as countries, I found the mixed palette superior to main:

iris %>%
  ggplot(.) + geom_point(
    aes(x=Sepal.Width, y=Sepal.Length, color=Species)
    ) +
  scale_color_icae(palette = "mixed", discrete = T) + 
  theme_minimal()

The new ggplot theme

The package also features a new theme for ggplot2 objects, called theme_icae. It includes a number of changes that I found useful in improving plot appearance in general, but it is not specifically built to fit the ICAE color scheme.

classic_theme_plot <- iris %>%
  ggplot(.) + geom_point(
    aes(x=Sepal.Width, y=Sepal.Length, color=Species)
    ) +
  ggtitle("The standard ggplot theme") +
  scale_color_icae(palette = "mixed", discrete = T)

icae_theme_plot <- iris %>%
  ggplot(.) + geom_point(
    aes(x=Sepal.Width, y=Sepal.Length, color=Species)
    ) +
  ggtitle("The theme_icae() appearance") +
  scale_color_icae(palette = "mixed", discrete = T) + 
  theme_icae()

ggpubr::ggarrange(classic_theme_plot, icae_theme_plot, 
                  ncol = 2, nrow = 1, common.legend = F)

It also features acceptable defaults for non-standard specifications such as wrapped plots:

classic_theme_plot <- iris %>%
  ggplot(.) + geom_point(
    aes(x=Sepal.Width, y=Sepal.Length)
    ) +
  ggtitle("The standard ggplot theme") +
  scale_color_icae(palette = "mixed", discrete = T) + 
  facet_wrap(~Species)

icae_theme_plot <- iris %>%
  ggplot(.) + geom_point(
    aes(x=Sepal.Width, y=Sepal.Length)
    ) +
  ggtitle("The theme_icae() appearance") +
  scale_color_icae(palette = "mixed", discrete = T) + 
  facet_wrap(~Species) +
  theme_icae()

ggpubr::ggarrange(classic_theme_plot, icae_theme_plot, 
                  ncol = 1, nrow = 2, common.legend = F)


graebnerc/icaeDesign documentation built on Feb. 29, 2024, 5:02 p.m.