Learn R Programming

ggthemr (version 1.0.2)

define_palette: Create ggthemr palette

Description

Create a custom palette that can be used by ggthemr. Checks will be carried out to make sure colours are not duplicated and are appropriate (e.g. the text colour should not match the background colour or text will not be visible).

Default colours for the background, text, axes lines and gridlines have been provided, but it is recommended that you overwrite these to make a nice theme.

Usage

define_palette(swatch, gradient, background = "#ffffff", text = c("#444444", "#444444"), line = c("#6e6e6e", "#6e6e6e"), gridline = "#c3c3c3")

Arguments

swatch
Vector of colours used for plotting data i.e. the main colours used for the points in geom_point(), bars in geom_bar() etc.
gradient
Vector of length two specifiying the lower and upper colours used for gradients.
background
Background colour.
text
Text colour. This should be either a single colour or a vector of two colours (see details).
line
Axes line colour. This should be either a single colour or a vector of two colours (see details).
gridline
Major and minor gridline colours.

Value

Object of type ggthemr_palette that you can pass to ggthemr().

Details

The text and axes line colours can both be provided as single colours or vectors of two colours. If only one colour is provided then the text and line colours will be identical regardless of the theme type ("inner" or "outer", see ggthemr for more details). Where your palette doesn't really need different text/line colours for the theme type than it sufficient to supply only one colour but a warning will be issued.

Vectors supplied for the text and line colours can have elements named "inner" and "outer". In the absence of these names, the first will be assumed to be the "inner" colour, the second will be the "outer" colour.

Examples

Run this code
# Create ugly theme with primary colours.
ugly <- define_palette(
  swatch = c('black', 'red', 'green', 'blue', 'brown', 'purple', 'yellow'), 
  gradient = c(lower = 'red', upper = 'green')
)
  
ggthemr(ugly)

Run the code above in your browser using DataLab