-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
558 lines (428 loc) · 15.7 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
---
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%"
)
```
# MexBrewer [<img src="man/figures/MexBrewer.png" align="right" width=300 />](https://paezha.github.io/MexBrewer/)
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/MexBrewer)](https://CRAN.R-project.org/package=MexBrewer)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![GitHub Stars](https://img.shields.io/github/stars/paezha/MexBrewer?style=social)](https://github.com/paezha/MexBrewer/stargazers)
![GitHub search hit counter: R](https://img.shields.io/github/search/paezha/MexBrewer/R)
![GitHub search hit counter: dataviz](https://img.shields.io/github/search/paezha/MexBrewer/dataviz)
![GitHub search hit counter: colors](https://img.shields.io/github/search/paezha/MexBrewer/colors)
![GitHub search hit counter: rtistry](https://img.shields.io/github/search/paezha/MexBrewer/rtistry)
![GitHub issues](https://img.shields.io/github/issues/paezha/MexBrewer)
![GitHub release](https://img.shields.io/github/release-date/paezha/MexBrewer)
![GitHub commit activity](https://img.shields.io/github/commit-activity/y/paezha/MexBrewer)
![GitHub last commit](https://img.shields.io/github/last-commit/paezha/MexBrewer)
[![](https://cranlogs.r-pkg.org/badges/mexbrewer)](https://cran.r-project.org/package=mexbrewer)
<!-- badges: end -->
MexBrewer is a package with color palettes inspired by the works of
Mexican painters and muralists. This package was motivated and draws heavily from the code of [Blake R. Mills](https://github.com/BlakeRMills/)'s
[{MetBrewer}](https://github.com/BlakeRMills/MetBrewer), the package with color
palettes form the Metropolitan Museum of Art of New York. The structure of the package and coding, like {MetBrewer}, are based on [{PNWColors}](https://github.com/jakelawlor/PNWColors) and [{wesanderson}](https://github.com/karthik/wesanderson).
## Installation
The package is available from CRAN:
```r
install.packages("MexBrewer")
```
The development version of the package can be installed like so:
``` r
if (!require("remotes")) install.packages("remotes")
remotes::install_github("paezha/MexBrewer")
```
## Artists
### Electa Arenal
#### Revolución
This palette is called `Revolucion`.
```{r revolucion, echo=FALSE, out.width="400px", fig.cap="Revolucion"}
knitr::include_graphics("man/figures/electa_arenal_revolucion.jpg")
```
```{r revolucion-palette, echo=FALSE, out.width="185px", fig.cap="Revolucion"}
knitr::include_graphics("man/figures/revolucion.png")
```
***
### Olga Costa
#### Naturaleza
This palette is called `Naturaleza`.
```{r naturaleza, echo=FALSE, out.width="400px", fig.cap="Naturaleza"}
knitr::include_graphics("man/figures/olga_costa_naturaleza.jpg")
```
```{r naturaleza-palette, echo=FALSE, out.width="185px", fig.cap="Naturaleza"}
knitr::include_graphics("man/figures/naturaleza.png")
```
#### Ofrenda
This palette is called `Ofrenda`.
```{r ofrenda, echo=FALSE, out.width="400px", fig.cap="Ofrenda"}
knitr::include_graphics("man/figures/olga_costa_ofrenda.jpg")
```
```{r ofrenda-palette, echo=FALSE, out.width="185px", fig.cap="Ofrenda"}
knitr::include_graphics("man/figures/ofrenda.png")
```
#### Vendedora
This palette is called `Vendedora`.
```{r vendedora, echo=FALSE, out.width="400px", fig.cap="Vendedora"}
knitr::include_graphics("man/figures/olga_costa_vendedora.jpg")
```
```{r vendedora-palette, echo=FALSE, out.width="185px", fig.cap="Vendedora"}
knitr::include_graphics("man/figures/vendedora.png")
```
***
### María Izquierdo
#### Alacena
This palette is called `Alacena`.
```{r alacena, echo=FALSE, out.width="400px", fig.cap="Alacena"}
knitr::include_graphics("man/figures/maria_izquierdo_alacena.jpg")
```
```{r alacena-palette, echo=FALSE, out.width="185px", fig.cap="Alacena"}
knitr::include_graphics("man/figures/alacena.png")
```
#### La Tierra
This palette is called `Tierra`.
```{r tierra, echo=FALSE, out.width="400px", fig.cap="Tierra"}
knitr::include_graphics("man/figures/maria_izquierdo_tierra.jpg")
```
```{r tierra-palette, echo=FALSE, out.width="185px", fig.cap="Tierra"}
knitr::include_graphics("man/figures/tierra.png")
```
***
### Frida Khalo
#### La Casa Azul
These palettes are called `Casita1`, `Casita2`, and `Casita3`. They are inspired by the colors of [Frida's home](https://www.museofridakahlo.org.mx/museo/) in Coyoacán, Mexico City.
```{r casa-azul-1, echo=FALSE, out.width="400px", fig.cap="Casa Azul"}
knitr::include_graphics("man/figures/casa-azul-1.jpg")
```
```{r casa-azul-2, echo=FALSE, out.width="400px", fig.cap="Casa Azul"}
knitr::include_graphics("man/figures/casa-azul-2.jpg")
```
```{r casa-azul-3, echo=FALSE, out.width="400px", fig.cap="Casa Azul"}
knitr::include_graphics("man/figures/casa-azul-3.jpg")
```
```{r casa-azul-4, echo=FALSE, out.width="400px", fig.cap="Casa Azul"}
knitr::include_graphics("man/figures/casa-azul-4.jpg")
```
```{r casa-azul-5, echo=FALSE, out.width="400px", fig.cap="Casa Azul"}
knitr::include_graphics("man/figures/casa-azul-5.jpg")
```
```{r casa-azul-6, echo=FALSE, out.width="400px", fig.cap="Casa Azul"}
knitr::include_graphics("man/figures/casa-azul-6.jpg")
```
```{r casita-1-palette, echo=FALSE, out.width="185px", fig.cap="Casita1"}
knitr::include_graphics("man/figures/casita-1.png")
```
```{r casita-2-palette, echo=FALSE, out.width="185px", fig.cap="Casita2"}
knitr::include_graphics("man/figures/casita-2.png")
```
```{r casita-3-palette, echo=FALSE, out.width="185px", fig.cap="Casita3"}
knitr::include_graphics("man/figures/casita-3.png")
```
***
### Rina Lazo
#### Venerable Abuelo Maiz
This palette is called `Maiz`.
```{r maiz, echo=FALSE, out.width="400px", fig.cap="Maiz"}
knitr::include_graphics("man/figures/rina_lazo_maiz.jpg")
```
```{r maiz-palette, echo=FALSE, out.width="185px", fig.cap="Maiz"}
knitr::include_graphics("man/figures/maiz.png")
```
***
### Fanny Rabel
#### La Ronda del Tiempo
This palette is called `Ronda`.
```{r ronda, echo=FALSE, out.width="400px", fig.cap="Ronda"}
knitr::include_graphics("man/figures/fanny_rabel_ronda.jpg")
```
```{r ronda-palette, echo=FALSE, out.width="185px", fig.cap="Ronda"}
knitr::include_graphics("man/figures/ronda.png")
```
***
### Aurora Reyes
#### El atentado a las maestras rurales
This palette is called `Atentado`.
```{r echo=FALSE, out.width="400px", fig.cap="Aurora, Concha, y Frida"}
knitr::include_graphics("man/figures/aurora_reyes_atentado.jpeg")
```
```{r echo=FALSE, out.width="185px", fig.cap="Aurora"}
knitr::include_graphics("man/figures/atentado.png")
```
#### Aurora, Concha, y Frida
This work of Aurora Rivera inspired three palettes, called `Aurora`, `Concha`, and `Frida`.
```{r auroa-concha-frida, echo=FALSE, out.width="400px", fig.cap="Aurora, Concha, y Frida"}
knitr::include_graphics("man/figures/aurora_concha_frida.jpg")
```
```{r aurora-palette, echo=FALSE, out.width="185px", fig.cap="Aurora"}
knitr::include_graphics("man/figures/aurora.png")
```
```{r concha-palette, echo=FALSE, out.width="185px", fig.cap="Concha"}
knitr::include_graphics("man/figures/concha.png")
```
```{r frida-palette, echo=FALSE, out.width="185px", fig.cap="Frida"}
knitr::include_graphics("man/figures/frida.png")
```
***
### Remedios Varo
#### La Huida
This palette is called `Huida`.
```{r echo=FALSE, out.width="400px", fig.cap="La Huida"}
knitr::include_graphics("man/figures/remedios_varo_huida.jpg")
```
```{r echo=FALSE, out.width="185px", fig.cap="Huida"}
knitr::include_graphics("man/figures/huida.png")
```
#### Taurus
This work of Remedios Varo inspired two palettes, called `Taurus1` and `Taurus2`.
```{r Taurus, echo=FALSE, out.width="400px", fig.cap="Taurus"}
knitr::include_graphics("man/figures/remedios_varo_taurus.jpg")
```
```{r taurus1-palette, echo=FALSE, out.width="185px", fig.cap="Taurus1"}
knitr::include_graphics("man/figures/taurus1.png")
```
```{r taurus2-palette, echo=FALSE, out.width="185px", fig.cap="Taurus2"}
knitr::include_graphics("man/figures/taurus2.png")
```
***
## Examples
```{r load-packges, message=FALSE, warning=FALSE}
library(aRtsy) # Koen Derks' package for generative art
library(flametree) # Danielle Navarro's package for generative art
library(MexBrewer)
library(sf)
library(tidyverse)
```
Invoke data sets used in the examples:
```{r load-data}
data("mx_estados") # Simple features object with the boundaries of states in Mexico
data("df_mxstate_2020") # Data from {mxmaps }with population statistics at the state level
```
Join population statistics to state boundaries:
```{r prepare-data}
mx_estados <- mx_estados |>
left_join(df_mxstate_2020 |>
#Percentage of population that speak an indigenous language
mutate(pct_ind_lang = indigenous_language/pop * 100) |>
dplyr::transmute(pop2020 = pop,
am2020 = afromexican,
state_name,
pct_ind_lang),
by = c("nombre" = "state_name"))
```
Distribution of population by geographic region in Mexico:
```{r population-distribution}
ggplot(data = mx_estados,
aes(x = region, y = pop2020, fill = region)) +
geom_boxplot() +
scale_fill_manual(values = mex.brewer("Concha", n = 5)) +
theme_minimal()
```
Percentage of population who speak an indigenous language in 2020 by state:
```{r indigenous-languages}
ggplot() +
geom_sf(data = mx_estados,
aes(fill = pct_ind_lang),
color = "white",
size = 0.08) +
scale_fill_gradientn(colors = mex.brewer("Tierra")) +
theme_minimal()
```
# Some Rtistry
### Danielle Navarro's [{flametree}](https://github.com/djnavarro/flametree)
The following three images were created using the {flametree} package.
```{r flametree-1, cache=TRUE}
# pick some colours
shades <- MexBrewer::mex.brewer("Vendedora") |>
as.vector()
# data structure defining the trees
dat <- flametree_grow(seed = 3563,
time = 11,
trees = 10)
# draw the plot
dat |>
flametree_plot(
background = shades[1],
palette = shades[2:length(shades)],
style = "nativeflora"
)
```
```{r flametree-2, cache=TRUE}
# pick some colours
shades <- MexBrewer::mex.brewer("Concha") |>
as.vector()
# data structure defining the trees
dat <- flametree_grow(seed = 3536,
time = 8,
trees = 6)
# draw the plot
dat |>
flametree_plot(
background = shades[1],
palette = rev(shades[2:length(shades)]),
style = "wisp"
)
```
```{r flametree-3, cache=TRUE}
# pick some colours
shades <- MexBrewer::mex.brewer("Maiz") |>
as.vector()
# data structure defining the trees
dat <- flametree_grow(seed = 3653,
time = 8,
trees = 6)
# draw the plot
dat |>
flametree_plot(
background = shades[1],
palette = shades[2:length(shades)],
style = "minimal"
)
```
### Koen Derks's [aRtsy](https://github.com/koenderks/aRtsy)
The following three images were created using the {aRtsy} package.
Functions:
```{r aRtsy-1, cache=TRUE}
my_formula <- list(
x = quote(runif(1, -1, 1) * x_i^2 - sin(y_i^2)),
y = quote(runif(1, -1, 1) * y_i^3 - cos(x_i^2))
)
canvas_function(colors = mex.brewer("Atentado"),
polar = FALSE,
by = 0.005,
formula = my_formula)
```
Mosaic:
```{r aRtsy-2, cache=TRUE}
canvas_squares(colors = mex.brewer("Alacena"),
cuts = 20,
ratio = 1.5,
resolution = 200,
noise = TRUE)
```
Mandelbrot's set:
```{r aRtsy-3, cache=TRUE}
canvas_mandelbrot(colors = mex.brewer("Naturaleza"),
zoom = 8,
iterations = 200,
resolution = 500)
```
### Meghan S. Harris's [waves](https://thetidytrekker.com/rtistry.html)
These plots are adaptations of Meghan Harris's artsy waves. Create data frames with wave functions:
```{r}
##Set up the "range" on the x axis for horizontal waves=====
wave_theta <- seq(from = -pi,
to = -0,
by = 0.01)
# Create waves using functions
wave_1 <- data.frame(x = wave_theta) |>
mutate(y = (sin(x) * cos(2 * wave_theta) + exp(x * 2)))
wave_2 <- data.frame(x = wave_theta) |>
mutate(y = (0.5 * sin(x) * cos(2.0 * wave_theta) + exp(x)) - 0.5)
```
<!--
```{r}
ggplot() +
geom_ribbon(data = wave_1,
aes(x, min = y - 0.025,
ymax = y + 0.025),
color = "black",
fill = "orange") +
geom_ribbon(data = wave_2,
aes(x, min = y - 0.025,
ymax = y + 0.025),
color = "black",
fill = "blue")
```
-->
Define a function to convert a single wave into a set of `n` waves. The function takes a data frame with a wave function and returns a data frame with `n` waves:
```{r}
# Creating a function for iterations====
wave_maker <- function(wave_df, n, shift){
#Create an empty list to store our multiple dataframes(waves)#
wave_list<- list()
#Create a for loop to iteratively make "n" waves shifted a distance `shift` from each other #
for(i in seq_along(1:n)){
wave_list[[i]] <- wave_df |>
mutate(y = y - (shift * i),
group = i)
}
#return the completed data frame to the environment#
return(bind_rows(wave_list))
}
```
Create layered waves using the data frames with the wave functions above:
```{r}
wave_layers <- rbind(wave_1 |>
wave_maker(n = 5,
shift = 0.075),
wave_2 |>
wave_maker(n = 5,
shift = 0.075) |>
mutate(group = group + 5)) # adjust the group counter to identify waves uniquely
```
Plot layered waves using cartesian coordinates and palette `Ofrenda`:
```{r}
ggplot(wave_layers) +
geom_rect(aes(xmin = -pi,
xmax = -0.0,
ymin = min(y) - 0.50,
ymax = max(y) + 0.30 ),
size = 2.5,
color = mex.brewer("Ofrenda")[6],
fill = mex.brewer("Ofrenda")[4]) +
geom_rect(aes(xmin = -pi,
xmax = -0.0,
ymin = min(y) - 0.50,
ymax = max(y) + 0.30 ),
size = 1,
color = "black",
fill = NA) +
geom_ribbon(aes(x,
ymin = y - 0.025 * 4 * x,
ymax = y + 0.015 * 10 * x,
group = group,
fill = group),
color = "black",
size = 0.5) +
scale_fill_gradientn(colors = mex.brewer("Ofrenda"))+
theme_void() +
theme(legend.position = "none")
```
Plot layered waves using polar coordinates and palette `Atentado`:
```{r}
ggplot(wave_layers) +
geom_rect(aes(xmin = -pi,
xmax = -0.0,
ymin = min(y) - 0.45,
ymax = max(y) + 0.30 ),
size = 2.5,
color = mex.brewer("Atentado")[6],
fill = mex.brewer("Atentado")[3]) +
geom_rect(aes(xmin = -pi,
xmax = -0.0,
ymin = min(y) - 0.45,
ymax = max(y) + 0.30 ),
size = 1,
color = "black",
fill = NA) +
geom_ribbon(aes(x,
ymin = y - 0.025 * 4 * x,
ymax = y + 0.015 * 10 * x,
group = group,
fill = group),
color = "black",
size = 0.5) +
scale_fill_gradientn(colors = mex.brewer("Atentado")) +
coord_polar(theta = "x",
start = 0,
direction = 1,
clip = "on") +
theme_void() +
theme(legend.position = "none")
```