R/discrete_colours.R

Defines functions discrete_colours

discrete_colours <- function(colours) {
  force(colours)
  function(n) {
    if (n > length(colours)) {
      stop("Your data requires ", n, " colours but the swatch provided by ggthemr only has ", 
                  length(colours), ". To resolve this you can provide an appropriate vector of colours to your scale or expand the swatch using set_swatch(). Note: if you are using a custom palette, the first swatch colour is separate from the others. See the documentation for define_palette() and/or set_swatch()", call.=FALSE)
    } else {
      colours[1:n]
    }
  }
}
cttobin/ggthemr documentation built on April 19, 2022, 3:31 a.m.