This function will generate colour palettes of arbitrary size from an R base graphics color function, ColorBrewer named palette, color-hex.com palette ID or vector of named or hex colours. Also, a source image file (png or jpeg) or url can be used. Defaults to a nice Tableau-esque Orange->Blue divering or Stephen Few-esque Earth->Emerald...

make_palette(
  colour = NULL,
  n = 7,
  reverse = FALSE,
  shuffle = FALSE,
  default = TRUE
)

Arguments

colour

colour(s) to be turned into a palette

n

numeric the number of colours to be returned

reverse

logical should the return palette order be reversed?

shuffle

logical should the return palette be shuffled?

default

logical should default palette be Tableau-esque orange-blue diverging?

Value

list object containing palette and plot

Examples


### Brewer Colour Palette 
make_palette(colour = 'Spectral')
#> #9E0142
#> #E95D47
#> #FDBE6E
#> #FFFFBF
#> #BEE5A0
#> #54AEAC
#> #5E4FA2

###  color-hex.com palette ID
make_palette(colour = 1010612)
#> #7EE787
#> #3ACA95
#> #26999F
#> #4254A7
#> #262B8A
#> #46106B
#> #A1024A
make_palette(colour = 1040526)
#> #475E3E
#> #1C4456
#> #3E6488
#> #AEC1D2
#> #988FB2
#> #7F708D
#> #636363

### Custom Colour Vector
my_colours <- c("#CAF60D", "#18D33A", "#4255EC", "#E60873", "#19312A")
make_palette(colour = my_colours)
#> #CAF60D
#> #53DE2A
#> #26A975
#> #4255EC
#> #AF219B
#> #A1155A
#> #19312A

### Sample Source Image
make_palette(colour = "https://www.r-project.org/Rlogo.png")
#> #000000
#> #2165B9
#> #6981A3
#> #A5A6AB
#> #B5B7BB
#> #C2C4C7
#> #FEFFFF

### Default Behaviour
make_palette(default = TRUE)
#> Empty or Unknown Colour(s)... 
#>   Defaulting to Tableau-style 
#>   Orange-Blue Diverging Palette
#> #7B3014
#> #D04A07
#> #F98C40
#> #C8C9CA
#> #5AA5CD
#> #236CA7
#> #26456E
make_palette(default = FALSE)
#> Empty or Unknown Colour(s)... 
#>   Defaulting to Stephen Few-style 
#>   Earth-Emerald Diverging Palette
#> #3E2B09
#> #6D501A
#> #A89355
#> #C8C9CA
#> #65C39E
#> #479D88
#> #1C5C4E