pal_ecology(n, palette)

Return a vector of n ecologically-themed colours. Palettes: 'biome', 'ocean', 'threat', 'realm'. Built on RColorBrewer with custom extensions.

visualizationutility
Args:n — number of colourspalette="biome"
pal_ecology <- function(n = 8, palette = "biome") {
  palettes <- list(
    biome  = c("#2e7d32","#1565c0","#f9a825","#6a1550",
               "#bf360c","#0277bd","#558b2f","#4e342e"),
    ocean  = c("#003f5c","#2f4b7c","#665191","#a05195",
               "#d45087","#f95d6a","#ff7c43","#ffa600"),
    threat = c("#d32f2f","#f57c00","#fbc02d","#388e3c",
               "#0288d1","#7b1fa2","#455a64","#795548"),
    realm  = c("#1b5e20","#0d47a1","#e65100","#880e4f",
               "#311b92","#004d40","#bf360c","#f57f17")
  )
  cols <- palettes[[palette]]
  if (is.null(cols)) stop("Unknown palette. Choose: ", paste(names(palettes), collapse=", "))
  if (n <= length(cols)) return(cols[1:n])
  colorRampPalette(cols)(n)
}

# Example
barplot(1:8, col = pal_ecology(8, "biome"))