-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
116 lines (93 loc) · 3.36 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# Colorblind-friendly Palettes from Washington State
<!-- badges: start -->
[![R-CMD-check](https://github.com/CoryMcCartan/wacolors/workflows/R-CMD-check/badge.svg)](https://github.com/CoryMcCartan/wacolors/actions)
[![CRAN](https://www.r-pkg.org/badges/version/wacolors)](https://CRAN.R-project.org/package=wacolors)
<!-- badges: end -->
![Mt. Rainier](cover.jpg)
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.
## Installation
You can install the released version of `wacolors` from
[CRAN](https://CRAN.R-project.org) with:
```r
install.packages("wacolors")
```
You can install the development version of `wacolors` from GitHub with:
``` r
devtools::install_github("CoryMcCartan/wacolors")
```
## Usage
It's easy to select a palette. Access palettes through `wacolors$...` for
autocompletion suggestions.
```{r}
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.
```{r ggplot, out.width=NULL}
# 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.
```{r heatmap, out.width=NULL}
image(volcano, col=wa_pal("ferries", 12))
image(volcano, col=wa_pal("vantage", 200, reverse=TRUE))
```
### Code Generation
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.
```{r}
pal_vector("sound_sunset", 15)
pal_functions("palouse")
```
## The Palettes
### Continuous Palettes
```{r cont-palettes, echo=F, fig.height=1, out.width=NULL}
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))
}
```
### Discrete Palettes
```{r disc-palettes, echo=F, fig.height=1, out.width=NULL}
for (pal in setdiff(names(wacolors), cont_pal)) {
plot(wa_pal(pal))
}
```