-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.qmd
190 lines (154 loc) · 4.32 KB
/
index.qmd
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
186
187
188
189
190
---
title: "The paletteer gallery"
format:
html:
toc: true
toc_float: true
editor_options:
chunk_output_type: console
---
```{css, echo=FALSE}
@import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap");
pre code {
font-family: "Roboto", sans-serif;
}
pre {
border-top: 0;
border-right: 0;
border-left: 0;
border-bottom: 5px solid #cecece;
}
```
```{r}
#| label: setup
#| include: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = NA,
warning = FALSE,
message = FALSE,
echo = FALSE,
dpi = 72,
dev = "png",
fig.height = 2,
fig.width = 8,
# fig.show='hold',
fig.align = "center"
)
library(tidyverse)
library(paletteer) # devtools::install_github("EmilHvitfeldt/paletteer")
library(glue)
```
```{r}
#| label: print-function
#| echo: false
#| output: asis
display_pal <- function(pkg, palette, n, pal_function) {
cat("<p><center>", glue("{pkg}::{palette}"), "</center></p>")
#
# if (palette == "contrast") browser()
n <- ifelse(is.na(n), 100, n)
par(mar = c(0.5, 0, 2, 0), family = "Exo")
image(
1:n,
1,
as.matrix(1:n),
col = do.call(pal_function, list(palette = glue("{pkg}::{palette}"), n = n)),
# main = glue("{palette} {{{pkg}}}"),
xlab = NA,
ylab = "",
xaxt = "n",
yaxt = "n",
bty = "n",
cex.main = 0.75
)
# The color and fill scales
f <- if (pal_function == "paletteer_d") {
c("scale_colour_paletteer_d", "scale_color_paletteer_d", "scale_fill_paletteer_d")
} else {
c("scale_colour_paletteer_c", "scale_color_paletteer_c", "scale_fill_paletteer_c")
}
v <- glue('<p>paletteer::{f}(\\"{pkg}::{palette}\\")</p>')
print(v)
v2 <- do.call(pal_function, list(palette = glue("{pkg}::{palette}"), n = n))
cat("<p>")
cat(glue('paletteer::{pal_function}(\\"{pkg}::{palette}\\")'))
cat("</p>")
cat("<p>")
cat(glue('[{{v2}}]{style="background-color:{{v2}};color:{{prismatic::best_contrast(v2)}}"}', .open = "{{", .close = "}}"))
cat("</p>")
cat("<hr/>")
}
display_pal <- safely(display_pal)
```
```{r}
#| label: list-palettes
df <- list(palettes_d_names, palettes_c_names) %>%
set_names(c("paletteer_d", "paletteer_c")) %>%
bind_rows(.id = "pal_function") %>%
as_tibble() %>%
select(2:5, 1)
```
```{r}
#| label: install-packages
#| eval: true
pkg_cran <- paletteer::paletteer_packages %>%
filter(CRAN == TRUE)
pkg_github <- paletteer::paletteer_packages %>%
filter(CRAN == FALSE)
# Use a safely function, so wont crash if a package is not found
safe_install <- safely(pak::pkg_install)
walk(pkg_cran$Name, safe_install)
walk(pkg_github$Github, safe_install)
```
```{r}
df <- df %>%
filter(package %in% installed.packages()) %>%
arrange(type, length)
```
The [paletteer](https://github.com/EmilHvitfeldt/paletteer) R package, from Emil Hvitfeldt is a collection of various color palettes found in different R packages.
> The goal of paletteer is to be a comprehensive collection of color palettes in R using a common interface. Think of it as the "caret of palettes".
This page is a simple gallery of these palettes. The are a total of `r nrow(df)` palettes (available from CRAN packages) divided into `discrete` and `continuous` scales. The titles of the following graphs present the `palette {package}`. There is also copy/pastable R code to use with ggplot2.
Based on paletteer version `r packageVersion("paletteer")`.
## Discrete palettes
### Diverging
```{r}
#| echo: false
#| output: asis
df %>%
filter(str_ends(pal_function, "_d") & (type == "diverging" | type == "divergent")) %>%
pwalk(~ display_pal(..1, ..2, ..3, ..5))
```
### Qualitative
```{r}
#| echo: false
#| output: asis
df %>%
filter(str_ends(pal_function, "_d") & type == "qualitative") %>%
pwalk(~ display_pal(..1, ..2, ..3, ..5))
```
### Sequential
```{r}
#| echo: false
#| output: asis
df %>%
filter(str_ends(pal_function, "_d") & (type == "sequential" | type == "sequantial")) %>%
pwalk(~ display_pal(..1, ..2, ..3, ..5))
```
## Continuous palettes
### Diverging
```{r}
#| echo: false
#| output: asis
df %>%
filter(str_ends(pal_function, "_c") & (type == "diverging" | type == "divergent")) %>%
pwalk(~ display_pal(..1, ..2, ..3, ..5))
```
### Sequential
```{r}
#| echo: false
#| output: asis
df %>%
filter(str_ends(pal_function, "_c") & (type == "sequential" | type == "sequantial")) %>%
pwalk(~ display_pal(..1, ..2, ..3, ..5))
```