-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
124 lines (87 loc) · 5.92 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
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/swatches)](https://cran.r-project.org/package=swatches)
[![Build Status](https://travis-ci.org/hrbrmstr/swatches.svg)](https://travis-ci.org/hrbrmstr/swatches)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/swatches?branch=master&svg=true)](https://ci.appveyor.com/project/hrbrmstr/swatches)
[![Coverage Status](https://img.shields.io/codecov/c/github/hrbrmstr/swatches/master.svg)](https://codecov.io/github/hrbrmstr/swatches?branch=master)
[![](http://cranlogs.r-pkg.org/badges/swatches)](http://cran.rstudio.com/web/packages/swatches/index.html)
# swatches
Read, Inspect, Manipulate, and Save (ASE) Color Swatch Files (ACO/ASE/GPL/SOC/KDE/COLORS)
## Description
In _Envisioning Information_, Edward Tufte says _"…avoiding catastrophe becomes the first principle in bringing color to information: Above all, do no harm."_ R users gain a quick upper hand in adhering to this "do no harm" thanks to sane defaults in `ggplot2` and packages like `viridis`, `ggthemes` or `RColorBrewer` that enable use of established and good color palettes.
If you do visualization work in conjunction with a design shop or organization that establishes their own palettes and themes there will often be standard palettes that must be adhered to. These are usually stored and shared in some type of Adobe swatch file format. There are also many sites like [Adobe Color CC](https://color.adobe.com/) and [COLOUR Lovers](https://www.colourlovers.com/) where folks can create and share color palettes. Plus, there are thousands of other palette files in dozens of palette formates.
This package enables you to use the colors straight from `.ase`, `.aso`, `.gpl`, `.soc` or `.color` files and avoid the cutting/pasting of hex codes or using color pickers to extract the color information. You can read these swatch files directly from the internet and/or include the files directly in your R projects. This will make it easier to modify a resource versus change code.
NOTE that just beacuse an ASE, ACO, GPL, SOC or color file exists on the internet does _not_ mean that it will let you "do no harm". You still need to use good judgement from knowledge/experience (or advice from experts) to ensure you are using colors effectively. This package just opens up the world of colors in R a little bit more.
## What's Inside The Tin
The following functions are implemented:
- `read_palette`: Generic function to read any supported palette type (determined by extension)
- `read_aco`: Read colors from Adobe Color (ACO) files
- `read_ase`: Read colors from Adobe Swatch Exchange (ASE) files
- `read_gpl`: Read GIMP Palette (GPL) files
- `read_soc`: Read OpenOffice palette (SOC) files
- `read_kde`: Read KDE Palette (colors) files
- `show_palette`: Display a color palette
- `add_color`: Add a named color to an ASE swatch object
- `ase_encode`: Encode a built ASE object for output
- `create_ase`: Create an ASE object
- `hex_to_ase`: Convert a list of named, hexadecimal RBG colors into an ASE object
### TODO
- ACO/ASE Grayscale support (just need to find or gen Grayscale ASE/ACO files, if you have a few please hook me up)
- ACO/ASE LAB support (could use some help with this)
- Writing out palette files (somewhat done!)
## Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/swatches")
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=80)
```
## Usage & Exposition
```{r}
library(swatches)
# current verison
packageVersion("swatches")
```
One good source for palettes is the ["Most Popular" section](https://color.adobe.com/explore/most-popular/?time=all) on Adobe Color CC. If you use the Adobe ecosystem, you can sync ASE palette files directly locally or download them directly (registration required).
![](img/adobe01.png)
The "Herbs and Spice" and "Keep the Change" palettes are kinda nifty, and also included in this package (since Adobe has yet to release the new API for the color site for automatic downloading). We can take a quick look at both of them. Here they are from the web site:
![](img/hns.png)
![](img/ktc.png)
And, there they are via this package:
```{r fig.height=2.5}
herbs_and_spice <- read_ase(system.file("palettes", "herbs_and_spice.ase", package="swatches"))
print(herbs_and_spice)
show_palette(herbs_and_spice)
```
```{r fig.height=2.5}
keep_the_change <- read_ase(system.file("palettes", "keep_the_change.ase", package="swatches"))
print(keep_the_change)
show_palette(keep_the_change)
```
As said earlier, you can also read directly from a URL. Here is a "metal" palette ripped straight [from github](https://github.com/picwellwisher12pk/en_us/):
```{r fig.height=2.5}
metal <- read_ase("https://github.com/picwellwisher12pk/en_us/raw/master/Swatches/Metal.ase")
print(metal)
show_palette(metal)
```
As you can see, this "metal" palette actually had named colors (albeit bland, CMYK value names).
Some palettes, like the Omega Nebula (CC-BY-SA [davidgav](http://www.colourlovers.com/lover/davidgav/loveNote)) one included with the package, have license restrictions (the mind _boggles_), so be aware of that when blatantly using others' designs without attribution. David's palette has much better names:
```{r fig.height=2.5}
omega_nebula <- read_ase(system.file("palettes", "omega_nebula.ase", package="swatches"))
print(omega_nebula)
show_palette(omega_nebula)
```
You need to use `unname` (or `use_names=FALSE` in `read_ase` or `read_aco`) before using them as `values`:
```{r fig.height=4}
library(ggplot2)
gg <- ggplot(mtcars, aes(x=mpg, y=disp))
gg <- gg + geom_point(aes(col=factor(gear)), size=3)
gg <- gg + scale_color_manual(values=unname(keep_the_change))
gg <- gg + theme_bw()
gg
```
## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.