The package Vignette for the package rkicolors
is a simple documentation on how to use the package to create ggplot2
plots in line with the corportaty design of the Robert Koch Institut. Note however, that this theme is an unofficial application of the RKI Style and must not be used to fake RKI results.
Part of the package are two ggplot themes (theme_rki()
and theme_rki_void()
) as well as two ggplot scales (scale_fill_rki()
and scale_color_rki()
). The theme includes various color palettes based on the RKI corporate color ported to RGB.
library(devtools)
library(httr)
library(ggplot2)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(extrafont)
#> Registering fonts with R
library(maps)
library(mapdata)
Note: This guide assumes that you are behind a corporate firewall with a proxy server. If you are not, you might skip the httr
Proxy Configuration.
myproxy <- Sys.getenv("http_proxy")
httr::set_config(httr::use_proxy(myproxy))
devtools::install_github("lekroll/rkicolors")
library(rkicolors)
sampleplot <- ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) + geom_point()
sampleplot
sampleplot + theme_rki() + scale_color_rki()
Change the colors to a different, RKI based Palette:
sampleplot + theme_rki() + scale_color_rki("qualitative")
Apply the RKI Corporate “ScalaSans” Fonts to the Plot if they are available on the local machine. Note font_import()
may take a while, depending on the number of fonts installed on the local machine. As a limitation, only True Type Fonts are acceptable by extrafont
.
Check if Scala is available:
# uncomment only on first run
# font_import(prompt = FALSE)
# loadfonts()
fonttable() %>% as.data.frame() %>% filter(grepl("Scala", FullName)) %>% select(FamilyName,FullName,Bold,Italic,Symbol)
#> FamilyName FullName Bold Italic Symbol
#> 1 ScalaLF-Bold ScalaLF-Bold FALSE FALSE FALSE
#> 2 ScalaLF-Regular ScalaLF-Regular FALSE FALSE FALSE
#> 3 ScalaSansLF-Bold ScalaSansLF-Bold FALSE FALSE FALSE
#> 4 ScalaSansLF-Regular ScalaSansLF-Regular FALSE FALSE FALSE
Apply font to theme:
sampleplot +
theme_rki(base_family="ScalaSansLF-Regular", bold_family="ScalaSansLF-Bold", base_size = 10) +
scale_color_rki("qualitative")
The color schemes below can be applied using scale_fill_rki(COLOR_SCHEME_NAME)
. If the fill or color variable is not discrete, scale_fill_rki(COLOR_SCHEME_NAME, discrete=FALSE)
has to be used.
To apply the scales to continous outcomes, the parameter discrete=FALSE
has to bet used:
ggplot(iris, aes(y=Sepal.Width, x=Sepal.Length,color=Sepal.Width)) + geom_jitter(size=3) + guides(color=FALSE)+theme_rki(base_family = "ScalaSansLF-Regular",bold_family = "ScalaSansLF-Bold") + scale_color_rki("bluered",discrete=FALSE) + facet_grid(cols = vars(Species))
worldmap.df <- map_data("world") %>% filter(region!="Antarctica")
map <- ggplot(data = worldmap.df) +
geom_polygon(aes(x = long, y = lat, group = group, fill="All"), color = "white") +
coord_fixed() + guides(fill=FALSE) +
theme_rki(base_family="ScalaSansLF-Regular", bold_family="ScalaSansLF-Bold", base_size = 10) +
scale_fill_rki()
map
map + theme_rki_void()
theme_set(theme_rki(base_family="ScalaSansLF-Regular", bold_family="ScalaSansLF-Bold", base_size = 10))
sampleplot + scale_color_rki()