title: "SLUcolors" output: rmarkdown::html_vignette: default pdf_document: default vignette: > %\VignetteIndexEntry{SLUcolors} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown}
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
SLUcolors is a R a package that tries to make the use of officialy defined SLU-colors in R easy. The use of the SLU color palette can give a coherant SLU-look presentations, fact-sheets and other communication, especially combined with official templates for PowerPoint etc. For more info see https://internt.slu.se/en/support-services/administrative-support/communication/brand-guidelines/visual-identity/slu-colours/palette/
The easiest way to install package SLUcolors is to use remotes::install_github("kagervall/SLUcolors", build_vignettes = TRUE) from package remotes.
if (!require(remotes)) { install.packages(remotes) } remotes::install_github("kagervall/SLUcolors")
The function SLUpalette()
is used to get variants of the SLU color palette (or all 26 available colors).
A color palette is a vector of color codes that can be used in other functions. The vector returned by
SLUpalette()
is named using the swedish names of the color as defined by "Communication & marketing".
SLUpalette(palette) takes one parameter, palette, that can be either a character or an integer. When palette
is a character the allowed strings are: "red", "green", "blue", "yellow", "grey" or "all", this will return columns from the official palette. When palette is an integer it can take the values 1 to 5, this will return rows from the official palette.
The package also includes a color palette suitable for categorical data optimized for colorblind individuals. The palette includes 5 colors from the
Wong
(ref?) palette and the colors are not "official" SLU colors. This palette is returned by the call SLUpalette("wong_234516")
. If/when a categorical palette using official colors is defined the the wong_234516
will be deprecated.
library(colorspace) # For swatchplot() library(SLUcolors) # Get colomn from the palette = "Shades of color" reds <- SLUpalette("red") # Get a palette with 5 "Shades of red" reds # The returned value is a (by default) named vector. # Get rows from palette row1 <- SLUpalette(1) row2 <- SLUpalette(2) row3 <- SLUpalette(3) row4 <- SLUpalette(4) row5 <- SLUpalette(5) swatchplot("Deep 1" = row1, "Deep 2" = row2, "Clear1" = row3, "Clear2" = row4, "Light" = row5, "wong" = SLUpalette("wong_234516"))
Here are some simple examples of how to use the SLU colors in base plot.
h <- matrix(data = 1:9, nrow = 3, byrow = TRUE) # Bar plot using the green palette for the bars. Reverse the palette to get the lightest colors barplot(h, col = rev(SLUpalette("green")), main = "Palette green") # Bar plot using row 5 (light colors) from the palette. barplot(h, col = SLUpalette(5), main = "Row 5 (Light)")
The function theme_SLU(palette, dark) returns a theme that can be applied to a plot created with ggplot2. When the parameter dark is TRUE (the default) the theme will have a dark background and light foreground. Set dark to FALSE to get a light background and dark foreground. This function probably work best with the color based ("red", "green", "blue" or "yellow") themes. The goal of the theme is to get a plot that blends well with the official SLU templates for PowerPoint. Feedback on the design is welcome as I am a decent programmer and a lousy designer.
library(ggplot2) p1 <- ggplot(iris, mapping = aes(x = Sepal.Width, y = Sepal.Length)) p1 + labs(title = "Red on green") + geom_point(color = SLUpalette("red")["Hallon"]) + theme_SLU("green") cols <- SLUpalette(3) names(cols) <- NULL # Must remove names for scale_color_manual() p1 + labs(title = "Light blue, grouped by species") + geom_point(aes(colour = Species)) + scale_color_manual(values = cols) + theme_SLU("blue", dark = FALSE)
Simple example using wong_234516
palette with ggplot2
p2 <- ggplot(mtcars, mapping = aes(x = factor(carb))) p2 + geom_bar(stat = "count", fill = SLUpalette("wong_234516")) + xlab("Carburator type")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.