It’s been a long time coming, but swatches
? is now on CRAN.
What is “swatches”?
First off, swatches
has nothing to do with those faux-luxury brand Swiss-made timepieces. swatches
is all about color.
R/CRAN has plenty of color picking packages. The colourlovers
? ? by @thosjleeper is one of my favs. But, color palettes have been around for ages. Adobe has two: Adobe Color (ACO) and Adobe Swatch Exchange (ASE); GIMP has “GPL”; OpenOffice has “SOC” and KDE has the unimaginative “colors”. So. Many. Formats. Wouldn’t it be great if there were a package that read them all in with a simple read_palette()
function? Well, now there is.
I threw together a fledgling version of swatches
a few years ago to read in ACO files from a $DAYJOB at the time and it cascaded from there. I decided to resurrect it and get it on CRAN to support a forthcoming “year in review” post that will make its way to your RSS feeds on-or-about December 31st.
True Colors Shining Through
Let’s say you want to get ahead of the game in 2018 and start preparing to dazzle your audience by using a palette that incorporates PANTONE’s 2018 Color of the Year (yes, that’s “a thing”) : Ultra Violet.
If you scroll down there, you’ll see a download link for an ASE version of the palettes. We can skip that and start with some R code:
library(swatches)
library(hrbrthemes)
library(tidyverse)
download.file("https://www.pantone.com/images/pages/21348/adobe-ase/Pantone-COY18-Palette-ASE-files.zip", "ultra_violet.zip")
unique(dirname((unzip("ultra_violet.zip"))))
## [1] "./Pantone COY18 Palette ASE files"
## [2] "./__MACOSX/Pantone COY18 Palette ASE files"
dir("./Pantone COY18 Palette ASE files")
# [1] "PantoneCOY18-Attitude.ase" "PantoneCOY18-Desert Sunset.ase"
# [3] "PantoneCOY18-Drama Queen.ase" "PantoneCOY18-Floral Fantasies.ase"
# [5] "PantoneCOY18-Intrigue.ase" "PantoneCOY18-Kindred Spirits.ase"
# [7] "PantoneCOY18-Purple Haze.ase" "PantoneCOY18-Quietude.ase"
Ah, if only the designers cleaned up their ZIP file.
We’ve got eight palettes to poke at, and hopefully one will be decent enough to use for our plots.
Let’s take a look:
par(mfrow=c(8,1))
dir("./Pantone COY18 Palette ASE files", full.names=TRUE) %>%
walk(~{
pal_name <- gsub("(^[[:alnum:]]+-|\\.ase$)", "", basename(.x))
show_palette(read_palette(.x))
title(pal_name)
})
par(mfrow=c(1,1))
I had initially thought I’d go for “Attitude”, but f.lux kicked in and “Intrigue” warmed better, so let’s go with that one.
(intrigue <- read_palette("./Pantone COY18 Palette ASE files/PantoneCOY18-Intrigue.ase"))
## PANTONE 19-4053 TCX PANTONE 17-4328 TCX PANTONE 18-3838 TCX PANTONE 18-0324 TCX PANTONE 19-3917 TCX
## "#195190" "#3686A0" "#5F4B8B" "#757A4E" "#4E4B51"
## PANTONE 15-0927 TCX PANTONE 14-5002 TCX PANTONE 14-3949 TCX
## "#BD9865" "#A2A2A1" "#B7C0D7"
Having the PANTONE names is all-well-and-good, but those are going to be less-useful in a ggplot2
context due to the way factors are mapped to names in character color vectors in manual scales, so let’s head that off at the pass:
(intrigue <- read_palette("./Pantone COY18 Palette ASE files/PantoneCOY18-Intrigue.ase", use_names=FALSE))
## [1] "#195190" "#3686A0" "#5F4B8B" "#757A4E" "#4E4B51" "#BD9865" "#A2A2A1" "#B7C0D7"
Beautiful.
Let’s put our new color scale to work! We’ve got 8 colors to work with, but won’t need all of them (at least for a quick example):
ggplot(economics_long, aes(date, value)) +
geom_area(aes(fill=variable)) +
scale_y_comma() +
scale_fill_manual(values=intrigue) +
facet_wrap(~variable, scales = "free", nrow = 2, strip.position = "bottom") +
theme_ipsum_rc(grid="XY", strip_text_face="bold") +
theme(strip.placement = "outside") +
theme(legend.position=c(0.85, 0.2))
This is far from a perfect palette, but it definitely helped illustrate basic package usage without inflicting ocular damage (remember: I could have picked an obnoxious Christmas palette :-)
More Practical Uses
If your workplace or the workplace you’re consulting for has brand guidelines, then they likely have swatches in one of the supported formats. Lot’s do.
You can keep those colors swatches in their native format and try out different ones as your designers refresh their baseline styles.
FIN
As always, kick the tyres, file issues, questions or PRs and hopefully the package will help refresh some designs for all of us in the coming year.