Skip to contents

This function provides a convenient way to apply Microsoft themed colour scales and aesthetics to ggplot2 plots. The user can specify whether they want a continuous or discrete theme by providing the scale_type argument.

Usage

dr_theme_microsoft(
  scale_type = c("discrete", "continuous"),
  index = NULL,
  direction = c("forwards", "backwards"),
  guide = "colourbar",
  fallback_font = "sans"
)

Arguments

scale_type

A character string specifying the type of scale, either "continuous" or "discrete". Default is "discrete". Simply, is the data mapped to the colour or fill aesthetic discrete or continuous.

index

An optional numeric index or vector of indices to select specific colours from the Microsoft colour palette.

direction

A character string, either "forwards" or "backwards" specifying the direction of the colour or fill gradient for continuous scales. Default is "forwards".

guide

An optional character string specifying the type of guide to use for continuous scales. Default is "colourbar", but other values include "legend", and "none". A rule of thumb is if the data are continuous, "colourbar" should be used, and if the data are discrete then "legend" should be used.

fallback_font

Adds a fallback font of 'sans' in case user does not have required font (Segoe UI).

Value

A list containing the ggplot2 theme, fill scale, and colour scale.

Examples

# \donttest{
library(ggplot2)

# Example with continuous theme
ggplot(mtcars, aes(x = wt, y = mpg, colour = qsec)) +
  geom_point() +
  dr_theme_microsoft(scale_type = "continuous")


# Example with discrete theme
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
  geom_point() +
  dr_theme_microsoft(scale_type = "discrete")

  # }