knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The wacolor
package contains r length(wacolors::wacolors)
color palettes
taken from the landscapes and cities of Washington state. Colors were
extracted from a set of photographs, and then combined to form a set of
continuous and discrete palettes. Continuous palettes were designed to
be perceptually uniform, while discrete palettes were chosen to maximize
contrast at several different levels of overall brightness and saturation.
Each palette has been evaluated to ensure colors are distinguishable by
colorblind people.
Discrete palettes contain at most seven colors. Don't create graphics that use more than seven discrete colors. You can color a map with four. Anything more risks confusion. Consider differentiating through faceting or labels, instead.
You can install the released version of wacolors
from
CRAN with:
install.packages("wacolors")
You can install the development version of wacolors
from GitHub with:
devtools::install_github("CoryMcCartan/wacolors")
It's easy to select a palette. Access palettes through wacolors$...
for
autocompletion suggestions.
library(wacolors) library(ggplot2) # See all palettes names(wacolors) # See one palette wacolors$rainier
The package comes with ggplot2
-compatible scales which are easy to use.
# access by name ggplot(mtcars, aes(mpg, wt)) + geom_point(aes(color = factor(cyl), size=hp)) + scale_color_wa_d("rainier") # or access using `wacolors$...` ggplot(diamonds) + geom_bar(aes(x = cut, fill = clarity)) + scale_fill_wa_d(wacolors$sound_sunset, reverse=TRUE)
You can use the wa_pal
function to directly construct a discretized/binned
color scale.
image(volcano, col=wa_pal("ferries", 12)) image(volcano, col=wa_pal("vantage", 200, reverse=TRUE))
In case you do not wish to have wacolors
as a dependency, you may use the
pal_vector()
and pal_functions()
functions, which generate self-contained
code for using the palettes. When using RStudio, this code will be loaded,
ready to copy, at the console prompt.
pal_vector("sound_sunset", 15) pal_functions("palouse")
cont_pal = c("sound_sunset", "ferries", "forest_fire", "sea_star", "sea", "volcano", "baker", "diablo", "puget", "mountains", "gorge", "foothills", "footbridge", "olympic", "lopez", "vantage", "stuart") for (pal in cont_pal) { plot(wa_pal(pal, 256)) }
for (pal in setdiff(names(wacolors), cont_pal)) { plot(wa_pal(pal)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.