-
Notifications
You must be signed in to change notification settings - Fork 7
/
README.Rmd
185 lines (135 loc) · 6.18 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
output: github_document
bibliography: vignettes/bibliography.bib
---
<!-- 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 = NULL
)
Sys.setlocale("LC_MESSAGES", 'en_GB.UTF-8') # Force locale
```
# khroma <img width=120px src="man/figures/logo.png" align="right" />
<!-- badges: start -->
[![R-CMD-check](https://github.com/tesselle/khroma/workflows/R-CMD-check/badge.svg)](https://github.com/tesselle/khroma/actions)
[![codecov](https://codecov.io/gh/tesselle/khroma/branch/main/graph/badge.svg)](https://app.codecov.io/gh/tesselle/khroma)
[![CodeFactor](https://www.codefactor.io/repository/github/tesselle/khroma/badge/main)](https://www.codefactor.io/repository/github/tesselle/khroma/overview/main)
[![Dependencies](https://tinyverse.netlify.app/badge/khroma)](https://cran.r-project.org/package=khroma)
[![r-universe](https://tesselle.r-universe.dev/badges/khroma)](https://tesselle.r-universe.dev/khroma){.pkgdown-devel}
[![CRAN Version](https://www.r-pkg.org/badges/version/khroma)](https://cran.r-project.org/package=khroma){.pkgdown-release}
[![CRAN checks](https://badges.cranchecks.info/worst/khroma.svg)](https://cran.r-project.org/web/checks/check_results_khroma.html){.pkgdown-release}
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/khroma)](https://cran.r-project.org/package=khroma){.pkgdown-release}
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1472077.svg)](https://doi.org/10.5281/zenodo.1472077)
<!-- badges: end -->
## Overview
Color blindness affects a large number of individuals. When communicating scientific results color palettes must therefore be carefully chosen to be accessible to all readers.
This R package provides an implementation of @okabe2008, @tol2021 and @crameri2018 color schemes. These schemes are ready for each type of data (qualitative, diverging or sequential), with colors that are distinct for all people, including color-blind readers. This package also provides tools to simulate color-blindness and to test how well the colors of any palette are identifiable. To simulate color-blindness in production-ready R figures you may also be interested in the [**colorblindr**](https://github.com/clauswilke/colorblindr) package.
@tol2021 and @crameri2018 offer carefully chosen schemes, ready for each type of data, with colors that are:
* Distinct for all people, including color-blind readers,
* Distinct from black and white,
* Distinct on screen and paper,
* Matching well together,
* Citable and reproducible.
See `vignette("tol")` and `vignette("crameri")` for a more complete overview.
For specific uses, several scientific thematic schemes (geologic timescale, land cover, FAO soils, etc.) are implemented, but these color schemes may not be color-blind safe.
All these color schemes are implemented for use with base R **graphics** or [**ggplot2**](https://github.com/tidyverse/ggplot2) and [**ggraph**](https://github.com/thomasp85/ggraph).
---
```{r citation, echo=FALSE, comment='', results='asis'}
cite <- utils::citation("khroma")
print(cite, bibtex = FALSE)
```
## Installation
You can install the released version of **khroma** from [CRAN](https://CRAN.R-project.org):
```{r cran-installation, eval=FALSE}
install.packages("khroma")
```
And the development version from [GitHub](https://github.com/) with:
```{r gh-installation, eval=FALSE}
# install.packages("remotes")
remotes::install_github("tesselle/khroma")
```
## Usage
```{r packages}
## Install extra packages (if needed)
# install.packages("ggplot2"))
## Load packages
library(khroma)
```
<details>
<summary><strong>Available palettes</strong> (click to expand)</summary>
```{r info}
## Get a table of available palettes
info()
```
</details>
### Color palettes and scales
`color()` returns a function that when called with a single integer argument returns a vector of colors.
```{r usage}
## Paul Tol's bright color scheme
bright <- color("bright")
bright(7)
```
```{r usage-show, fig.height=2, fig.width=7, fig.align='center'}
## Plot the color scheme
plot_scheme(bright(7), colours = TRUE)
```
```{r usage-plot, fig.height=3.5, fig.width=5, fig.align='center'}
data(mpg, package = "ggplot2")
## Use with graphics
par(mar = c(5, 4, 1, 1) + 0.1)
plot(
x = mpg$displ,
y = mpg$hwy,
pch = 16,
col = palette_color_picker("bright")(mpg$class),
xlab = "displ",
ylab = "hwy",
panel.first = grid(),
las = 1
)
## Use with ggplot2
ggplot2::ggplot(data = mpg) +
ggplot2::aes(x = displ, y = hwy, color = class) +
ggplot2::geom_point() +
ggplot2::theme_bw() +
scale_color_bright()
```
### Diagnostic tools
#### Test how well the colors are identifiable
```{r usage-map, fig.height=2, fig.width=7, fig.align='center'}
## Okabe & Ito's color scheme
okabe <- color("okabe ito")
set.seed(12345)
plot_map(okabe(8))
```
```{r usage-tiles, fig.height=3, fig.width=3, fig.align='center'}
## BuRd sequential color scheme
BuRd <- color("BuRd")
plot_tiles(BuRd(128), n = 256)
```
#### Simulate color-blindness
```{r usage-colorblind1, echo=FALSE, eval=FALSE, fig.height=2, fig.width=7, fig.align='center'}
## change() returns function
deuteranopia <- change(okabe, mode = "deuteranopia")
plot_scheme(deuteranopia(8), colours = TRUE)
protanopia <- change(okabe, mode = "protanopia")
plot_scheme(protanopia(8), colours = TRUE)
tritanopia <- change(okabe, mode = "tritanopia")
plot_scheme(tritanopia(8), colours = TRUE)
achromatopsia <- change(okabe, mode = "achromatopsia")
plot_scheme(achromatopsia(8), colours = TRUE)
```
```{r usage-colorblind2, fig.height=4, fig.width=7, fig.align='center'}
plot_scheme_colorblind(okabe(8))
## ggplot2 default color scheme
## (equally spaced hues around the color wheel)
x <- scales::hue_pal()(8)
plot_scheme_colorblind(x)
```
## Contributing
Please note that the **khroma** project is released with a [Contributor Code of Conduct](https://www.tesselle.org/conduct.html). By contributing to this project, you agree to abide by its terms.
## References