<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/new-package-swatches-is-now-on-cran/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2017/12/21/new-package-swatches-is-now-on-cran/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>It’s been a long time coming, but <a rel="nofollow" href="https://github.com/hrbrmstr/swatches" target="_blank"><code>swatches</code><img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a> is now <a rel="nofollow" href="https://cran.r-project.org/web/packages/swatches/index.html" target="_blank">on CRAN</a>. </p>
<h2>What is “swatches”?</h2>
<p>First off, <code>swatches</code> has nothing to do with those faux-luxury brand Swiss-made timepieces. <code>swatches</code> is all about <span>c</span><span>o</span><span>l</span><span>o</span><span>r</span>.</p>
<p>R/CRAN has plenty of color picking packages. The <a rel="nofollow" href="https://cran.r-project.org/package=colourlovers" target="_blank"><code>colourlovers</code><img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a> <img alt="📦" src="https://i2.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f4e6.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"> by <a rel="nofollow" href="http://twitter.com/thosjleeper" target="_blank">@thosjleeper</a> 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 <code>read_palette()</code> function? Well, now there is.</p>
<p>I threw together a fledgling version of <code>swatches</code> 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. </p>
<h2>True Colors Shining Through</h2>
<p>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”) : <a rel="nofollow" href="https://www.pantone.com/color-of-the-year-2018-tools-for-designers" target="_blank">Ultra Violet</a>. </p>
<p>If you scroll down there, you’ll see a <a rel="nofollow" href="https://www.pantone.com/images/pages/21348/adobe-ase/Pantone-COY18-Palette-ASE-files.zip" target="_blank">download link</a> for an ASE version of the palettes. We can skip that and start with some R code:</p>
<pre><code>library(swatches)
library(hrbrthemes)
library(tidyverse)

download.file(&quot;https://www.pantone.com/images/pages/21348/adobe-ase/Pantone-COY18-Palette-ASE-files.zip&quot;, &quot;ultra_violet.zip&quot;)
unique(dirname((unzip(&quot;ultra_violet.zip&quot;))))
## [1] &quot;./Pantone COY18 Palette ASE files&quot;
## [2] &quot;./__MACOSX/Pantone COY18 Palette ASE files&quot;


dir(&quot;./Pantone COY18 Palette ASE files&quot;)
#  [1] &quot;PantoneCOY18-Attitude.ase&quot;         &quot;PantoneCOY18-Desert Sunset.ase&quot;   
#  [3] &quot;PantoneCOY18-Drama Queen.ase&quot;      &quot;PantoneCOY18-Floral Fantasies.ase&quot;
#  [5] &quot;PantoneCOY18-Intrigue.ase&quot;         &quot;PantoneCOY18-Kindred Spirits.ase&quot; 
#  [7] &quot;PantoneCOY18-Purple Haze.ase&quot;      &quot;PantoneCOY18-Quietude.ase&quot;</code></pre>
<p>Ah, if only the designers cleaned up their ZIP file. </p>
<p>We’ve got eight palettes to poke at, and hopefully one will be decent enough to use for our plots.</p>
<p>Let’s take a look:</p>
<pre><code>par(mfrow=c(8,1))

dir(&quot;./Pantone COY18 Palette ASE files&quot;, full.names=TRUE) %>% 
  walk(~{
    pal_name &lt;- gsub(&quot;(^[[:alnum:]]+-|\\.ase$)&quot;, &quot;&quot;, basename(.x))
    show_palette(read_palette(.x))
    title(pal_name)
  })

par(mfrow=c(1,1))</code></pre>
<p><a rel="nofollow" href="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png.png?ssl=1" target="_blank"><img data-orig-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png.png?fit=1342%2C2806&amp;ssl=1" data-orig-size="1342,2806" data-medium-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png.png?fit=143%2C300&amp;ssl=1" data-attachment-id="7715" data-image-meta="{" data-image-description="" src="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png.png?resize=780%2C1631&ssl=1" data-permalink="https://rud.is/b/2017/12/21/new-package-swatches-is-now-on-cran/plot_zoom_png-8/" data-large-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png.png?fit=490%2C1024&amp;ssl=1" alt="" data-image-title="plot_zoom_png" width="450" data-comments-opened="1" class="wp-image-7715" data-recalc-dims="1"></a></p>
<p>I had initially thought I’d go for “Attitude”, but <a rel="nofollow" href="https://www.r-bloggers.com/new-package-swatches-is-now-on-cran/://getflux.com" target="_blank">f.lux</a> kicked in and “Intrigue” warmed better, so let’s go with that one.</p>
<pre><code>(intrigue &lt;- read_palette(&quot;./Pantone COY18 Palette ASE files/PantoneCOY18-Intrigue.ase&quot;))
## PANTONE 19-4053 TCX PANTONE 17-4328 TCX PANTONE 18-3838 TCX PANTONE 18-0324 TCX PANTONE 19-3917 TCX 
##           &quot;#195190&quot;           &quot;#3686A0&quot;           &quot;#5F4B8B&quot;           &quot;#757A4E&quot;           &quot;#4E4B51&quot; 
## PANTONE 15-0927 TCX PANTONE 14-5002 TCX PANTONE 14-3949 TCX 
##           &quot;#BD9865&quot;           &quot;#A2A2A1&quot;           &quot;#B7C0D7&quot;</code></pre>
<p>Having the PANTONE names is all-well-and-good, but those are going to be less-useful in a <code>ggplot2</code> 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:</p>
<pre><code>(intrigue &lt;- read_palette(&quot;./Pantone COY18 Palette ASE files/PantoneCOY18-Intrigue.ase&quot;, use_names=FALSE))
## [1] &quot;#195190&quot; &quot;#3686A0&quot; &quot;#5F4B8B&quot; &quot;#757A4E&quot; &quot;#4E4B51&quot; &quot;#BD9865&quot; &quot;#A2A2A1&quot; &quot;#B7C0D7&quot;</code></pre>
<p>Beautiful.</p>
<p>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):</p>
<pre><code>ggplot(economics_long, aes(date, value)) +
  geom_area(aes(fill=variable)) +
  scale_y_comma() +
  scale_fill_manual(values=intrigue) +
  facet_wrap(~variable, scales = &quot;free&quot;, nrow = 2, strip.position = &quot;bottom&quot;) +
  theme_ipsum_rc(grid=&quot;XY&quot;, strip_text_face=&quot;bold&quot;) +
  theme(strip.placement = &quot;outside&quot;) +
  theme(legend.position=c(0.85, 0.2))</code></pre>
<p><a rel="nofollow" href="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png-1.png?ssl=1" target="_blank"><img data-orig-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png-1.png?fit=1820%2C1120&amp;ssl=1" data-orig-size="1820,1120" data-medium-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png-1.png?fit=300%2C185&amp;ssl=1" data-attachment-id="7717" data-image-meta="{" data-image-description="" src="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png-1.png?resize=780%2C480&ssl=1" data-permalink="https://rud.is/b/2017/12/21/new-package-swatches-is-now-on-cran/plot_zoom_png-9/" data-large-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/12/plot_zoom_png-1.png?fit=530%2C326&amp;ssl=1" alt="" data-image-title="plot_zoom_png" width="450" data-comments-opened="1" class="wp-image-7717" data-recalc-dims="1"></a></p>
<p>This is far from a perfect palette, but it definitely helped illustrate basic package usage without inflicting ocular damage (remember: I <em>could</em> have picked an obnoxious Christmas palette <img alt="🙂" src="https://s.w.org/images/core/emoji/2.3/72x72/1f642.png" class="wp-smiley"></p>
<h2>More Practical Uses</h2>
<p>If your workplace or the workplace you’re consulting for has brand guidelines, then they likely have swatches in one of the supported formats. <a rel="nofollow" href="https://www.google.com/search?q=brand+colors+swatches" target="_blank">Lot’s do</a>.</p>
<p>You can keep those colors swatches in their native format and try out different ones as your designers refresh their baseline styles.</p>
<h2>FIN</h2>
<p>As always, <a rel="nofollow" href="https://github.com/hrbrmstr/swatches" target="_blank">kick the tyres</a>, file issues, questions or PRs and hopefully the package will help refresh some designs for all of us in the coming year.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rud.is/b/2017/12/21/new-package-swatches-is-now-on-cran/"> R – rud.is</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/byW2WNA1HEg" height="1"></a></div>