Install using devtools::install_github("cjtexas/colourgen")
The colourgen
package provides a single, simple interface for generating colour palettes in R. colourgen::make_palette
is the main function and returns a colourgen
object with very handy plot
and print
methods to make generating, inspecting and fine-tuning color palettes a breeze.
The colour
parameter will accept any base R color function, RColorBrewer
named palette, viridis
named palette, color-hex palette ID or variable-length character vector of any combination of base grDevices::colours
and/or hexadecimal colors.
At the time I created this package there weren’t enough good diverging palettes and I tend to use them alot in my work, so colourgen
will default to some right out-of-the box.
my_palette <- colourgen::make_palette(default = FALSE)
## Empty or Unknown Colour(s)...
## Defaulting to Stephen Few-style
## Earth-Emerald Diverging Palette
plot(my_palette)
If you like tweaking your color palettes, you can easily do that. Let’s just simply replace the middle color with “ivory” and call colourgen::make_palette
again to check the new results.
my_palette[4] <- "ivory"
my_palette_mod <- colourgen::make_palette(colour = my_palette)
plot(my_palette_mod)
If you want to interpolate a palette that normally has a hard limit; don’t worry, colourgen
was created for this very reason and wil return as many colors as you need for your factor levels! NOTE:, you should still be careful and use common sense ;)
colourgen::make_palette(colour = "set1", n = 15)
colourgen
also supports the color-hex palette API. Just supply a valid paletteID and you can interpolate over that palette ’til your heart’s content.
colourgen::make_palette(colour = 1010612, n = 7)
colourgen
will also accept an image path or url. For example, let’s make a palette from the R logo!
colourgen::make_palette(colour = "http://r-project.org/Rlogo.png", n = 7)