library(colorpiler)
library(knitr)
library(ggplot2)
library(shiny)
theme_set(theme_bw())

Colorpile is a community-driven repository for color palettes. Color palettes are stored as json files containing the palette's colors and associated metadata. The colorpiler package lets users access and search these color palettes, use them in ggplot2 plots and elsewhere, contribute their own palettes.

Access and search

The colorpile_metadata function gives a data frame with all metadata about all of the color palettes in colorpile.

head(colorpile_metadata())

To get only those palettes that match certain search criteria, use the search_colorpile function to filter palettes by author(s), github username, or type.

search_colorpile(authors = c("Karthik Ram", "Ethan Schoonover"))
search_colorpile(authors = "Cynthia Brewer", type = "diverging")

Once you know the name of the color palette you want, use colorpile_palette to generate a function that gives a set of colors for a number of values.

darjeeling <- colorpile_palette("Darjeeling")
darjeeling(3)
darjeeling(5)

Viewing and plotting

Run the gadget browse_colorpile on a character vector of palette names to see what they look like.

browse_colorpile(search_colorpile(github_user = "karthik"))

Or run the gadget demo_colorpile to see what a sample plot looks like with various palettes.

demo_colorpile()

colorpiler provides color and fill scales for ggplot2. Just pass any colorpiler palette name to scale_color_colorpile or scale_fill_colorpile.

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
  geom_point() +
  scale_color_colorpile("Darjeeling")

Contribute

To create a color palette, pass create_palette all of the metadata about your palette and character vector of its colors.

create_palette(name = "best_ever",
               authors = "Alyssa P. Hacker",
               github_user = "ahacker",
               description = "Provides the best color palette of all time!",
               keywords = "awesome",
               colors = c("#000000", "#00FF00"),
               type = "qualitative")

This will create a json file specifying your palette, which you can then submit to colorpile by creating a pull request (stay tuned for this to happen automatically!).



ropenscilabs/colorpiler documentation built on May 18, 2022, 7:35 p.m.