<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/the-ggthemr-package-theme-and-colour-your-ggplot-figures/"></div></div><div><a data-url="http://www.r-bloggers.com/the-ggthemr-package-theme-and-colour-your-ggplot-figures/" data-counturl="http://www.r-bloggers.com/the-ggthemr-package-theme-and-colour-your-ggplot-figures/" data-count="horizontal" data-text="The ggthemr package – Theme and colour your ggplot figures" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/"> R – Shane Lynn </a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Theming ggplot figure output</h2>
<p>The default colour themes in ggplot2 are beautiful. Your figures look great, the colours match, and you have the characteristic “R” look and feel. The author of ggplot2, <a target="_blank" href="http://hadley.nz/">Hadley Wickham</a>, has done a fantastic job.</p>
<p>For the tinkerers, there’s methods to change every part of the look and feel of your figures. In practice however, changing all of the defaults can feel laborious and too much work when you want a quick change to look and feel.</p>
<p>The <a target="_blank" href="https://github.com/cttobin/ggthemr">ggthemr</a> package was developed by a friend of mine, <a target="_blank" href="https://github.com/cttobin">Ciarán Tobin</a>, who works with me at <a target="_blank" href="http://www.killbiller.com/">KillBiller</a> and <a target="_blank" href="http://www.edgetier.com/">Edgetier</a>. The package gives a quick and easy way to completely change the look and feel of your <a target="_blank" href="http://ggplot2.org/">ggplot2</a> figures, as well as quickly create a theme based on your own, or your company’s, colour palette.</p>
<p>In this post, we will quickly examine some of the built in theme variations included with ggplot2 in R, and then look at the colour schemes available using ggthemr.</p>
<h2>Basic themes included in ggplot2</h2>
<p>There’s 8 built-in theme variations in the latest versions of ggplot2. Quickly change the default look of your figures by adding theme_XX() to the end of your plotting commands.</p>
<p>Let’s look at some of these. First create a simple figure, based on the massively overused “iris” dataset, since it’s built-in to R.</p>
<pre># Define a set of figures to play with using the Iris dataset
point_plot &lt;- ggplot(iris, aes(x=jitter(Sepal.Width), y=jitter(Sepal.Length), col=Species)) + 
 geom_point() + 
 labs(x=&quot;Sepal Width (cm)&quot;, y=&quot;Sepal Length (cm)&quot;, col=&quot;Species&quot;, title=&quot;Iris Dataset&quot;)

bar_plot &lt;- ggplot(iris, aes(x=Species, y=Sepal.Width, fill=Species)) + 
 geom_bar(stat=&quot;summary&quot;, fun.y=&quot;mean&quot;) + 
 labs(x=&quot;Species&quot;, y=&quot;Mean Sepal Width (cm)&quot;, fill=&quot;Species&quot;, title=&quot;Iris Dataset&quot;)

box_plot &lt;- ggplot(iris, aes(x=Species, y=Sepal.Width, fill=Species)) + 
 geom_boxplot() + 
 labs(x=&quot;Species&quot;, y=&quot;Sepal Width (cm)&quot;, fill=&quot;Species&quot;, title=&quot;Iris Dataset&quot;)

# Display this figure:
point_plot
# Display this figure with a theme:
point_plot + theme_dark()</pre>
<p>The default look and feel can be adjusted by adding an in-build theme from ggplot2.</p>
<ul>
<li>theme_gray() – signature ggplot2 theme</li>
<li>theme_bw() – dark on light ggplot2 theme</li>
<li>theme_linedraw() – uses black lines on white backgrounds only</li>
<li>theme_light() – similar to linedraw() but with grey lines aswell</li>
<li>theme_dark() – lines on a dark background instead of light</li>
<li>theme_minimal() – no background annotations, minimal feel.</li>
<li>theme_classic() – theme with no grid lines.</li>
<li>theme_void() – empty theme with no elements</li>
</ul>
<p>Examples of these theme’s applied to the figure is shown below.</p>
<p><a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/theme_default/#main"><img sizes="(max-width: 750px) 100vw, 750px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_default.png" data-orig-size="1800,1200" data-image-title="theme_default" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="496" srcset="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_default-1024x683.png?resize=456%2C304 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_default-300x200.png 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_default-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_default-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_default-1140x760.png 1140w" alt="Default ggplot2 library theme scatter diagram" data-medium-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_default-300x200.png" data-large-file="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_default-1024x683.png?resize=456%2C304" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_default-1024x683.png?resize=456%2C304"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/theme_dark/#main"><img sizes="(max-width: 750px) 100vw, 750px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark.png" data-orig-size="1800,1200" data-image-title="theme_dark" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="499" srcset="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark-1024x683.png?resize=456%2C304 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark-300x200.png 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark-1140x760.png 1140w" alt="Scatter plot with theme_dark() from ggplot library" data-medium-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark-300x200.png" data-large-file="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark-1024x683.png?resize=456%2C304" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_dark-1024x683.png?resize=456%2C304"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/theme_light/#main"><img sizes="(max-width: 750px) 100vw, 750px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_light.png" data-orig-size="1800,1200" data-image-title="theme_light" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="497" srcset="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_light-1024x683.png?resize=456%2C304 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_light-300x200.png 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_light-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_light-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_light-1140x760.png 1140w" alt="Scatter diagram with &quot;theme_light()&quot;" data-medium-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_light-300x200.png" data-large-file="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_light-1024x683.png?resize=456%2C304" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_light-1024x683.png?resize=456%2C304"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/theme_void/#main"><img sizes="(max-width: 750px) 100vw, 750px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_void.png" data-orig-size="1800,1200" data-image-title="theme_void" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="501" srcset="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_void-1024x683.png?resize=456%2C304 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_void-300x200.png 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_void-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_void-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_void-1140x760.png 1140w" alt="Scatter plot with &quot;void&quot; or no theme." data-medium-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_void-300x200.png" data-large-file="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_void-1024x683.png?resize=456%2C304" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_void-1024x683.png?resize=456%2C304"></a></p>
<p>Note that the colour palette for your figures is not affected by these theme changes – only the figure parameters such as the grid lines, outlines, and backgrounds etc.</p>
<h2>The “ggthemr” package</h2>
<p>The <a target="_blank" href="https://github.com/cttobin/ggthemr">ggthemr R package</a> is an R package to set up a new theme for your ggplot figures, and completely change the look and feel of your figures, from colours to gridlines. The package is available on <a target="_blank" href="https://github.com/">github</a>, and is installed using the <a target="_blank" href="https://cran.r-project.org/web/packages/devtools/index.html">Devtools</a> package:</p>
<pre>library(devtools)
&lt;span class=&quot;s1&quot;>devtools&lt;/span>&lt;span class=&quot;s2&quot;>::&lt;/span>&lt;span class=&quot;s3&quot;>install_github(&lt;/span>&lt;span class=&quot;s4&quot;>'cttobin/ggthemr'&lt;/span>&lt;span class=&quot;s3&quot;>)&lt;/span></pre>

<p>The ggthemr package is built for “fire-and-forget” usage: you set the theme at the start of your R session, and all of your plots will look different from there.</p>
<p>The command to set a theme is:</p>
<pre># set ggthemr theme
ggthemr(&quot;&amp;lt;theme name&amp;gt;&quot;) 
# plot your existing figure with the new theme
plt
# to remove all ggthemr effects later:
ggthemr_reset()</pre>
<p>For example:</p>
<pre>library(ggthemr)
ggthemr(&quot;dust&quot;)
point_plot
bar_plot</pre>

<h2><a target="_blank" href="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust.png"><img sizes="(max-width: 450px) 100vw, 450px" srcset="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-300x200.png?resize=450%2C300 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-1140x760.png 1140w" alt="pointplot-dust.png" class="wp-image-584" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-300x200.png?resize=450%2C300" data-recalc-dims="1"></a><a target="_blank" href="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust.png"><img sizes="(max-width: 450px) 100vw, 450px" srcset="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-300x200.png?resize=450%2C300 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-1140x760.png 1140w" alt="barplot_dust.png" class="wp-image-583" src="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-300x200.png?resize=450%2C300" data-recalc-dims="1"></a></h2>
<h2>“ggthemr” colour themes</h2>
<p>There are 17 built-in colour themes with ggthemr, each one providing a unique way to change your ggplot figure look. All are listed on the <a target="_blank" href="https://github.com/cttobin/ggthemr">ggthemr github page</a>. The colour themes available built-in are:</p>
<ul>
<li>flat</li>
<li>flat-dark</li>
<li>camoflauge</li>
<li>chalk</li>
<li>copper</li>
<li>dust</li>
<li>earth</li>
<li>fresh</li>
<li>grape</li>
<li>grass</li>
<li>greyscale</li>
<li>light</li>
<li>lilac</li>
<li>pale</li>
<li>sea</li>
<li>sky</li>
<li>solarized</li>
</ul>
<p>One benefit of using ggthemr is that the default color palettes are replaced for lines and bars – completely changing the look of the charts. A complete view of all themes is available <a target="_blank" href="https://github.com/cttobin/ggthemr#palettes">here</a>, and some random examples are shown below.</p>
<div class="wp-caption"><a target="_blank" href="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_dust.png"><img sizes="(max-width: 1440px) 100vw, 1440px" srcset="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_dust.png?resize=456%2C160 1440w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dust-300x105.png 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dust-768x269.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dust-1024x358.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dust-732x256.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_dust-1140x399.png 1140w" alt="theme_dust.png" class="wp-image-591" src="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_dust.png?resize=456%2C160" data-recalc-dims="1"></a>
<p class="wp-caption-text">“Dust” look and feel across charts</p>
</div>
<div class="wp-caption"><a target="_blank" href="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_earth.png"><img sizes="(max-width: 1440px) 100vw, 1440px" srcset="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_earth.png?resize=456%2C160 1440w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_earth-300x105.png 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_earth-768x269.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_earth-1024x358.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_earth-732x256.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_earth-1140x399.png 1140w" alt="theme_earth.png" class="wp-image-592" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_earth.png?resize=456%2C160" data-recalc-dims="1"></a>
<p class="wp-caption-text">“Earth” look and feel colour palette for box plot, scatter diagram, and bar chart.</p>
</div>
<div class="wp-caption"><img sizes="(max-width: 1440px) 100vw, 1440px" srcset="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_flat.png?resize=456%2C160 1440w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_flat-300x105.png 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_flat-768x269.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_flat-1024x358.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_flat-732x256.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/theme_flat-1140x399.png 1140w" alt="theme_flat.png" class="wp-image-594" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/theme_flat.png?resize=456%2C160" data-recalc-dims="1">
<p class="wp-caption-text">“Flat” look and feel from ggthemr for various chart types</p>
</div>
<p><a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/pointplot-grass/#main"><img sizes="(max-width: 300px) 100vw, 300px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass.png" data-orig-size="1800,1200" data-image-title="pointplot-grass" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="595" srcset="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass-300x200.png?resize=300%2C200 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass-1140x760.png 1140w" alt="Scatter plot with &quot;grass&quot; ggthemr plot" data-medium-file="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass-300x200.png?resize=300%2C200" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-grass-300x200.png?resize=300%2C200"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/boxplot_pale/#main"><img sizes="(max-width: 300px) 100vw, 300px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale.png" data-orig-size="1800,1200" data-image-title="boxplot_pale" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="596" srcset="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale-300x200.png?resize=300%2C200 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale-1140x760.png 1140w" alt="Box plot with &quot;pale&quot; theme" data-medium-file="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale-300x200.png?resize=300%2C200" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_pale-300x200.png?resize=300%2C200"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/boxplot_solarized-2/#main"><img sizes="(max-width: 300px) 100vw, 300px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1.png" data-orig-size="1800,1200" data-image-title="boxplot_solarized" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="589" srcset="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1-300x200.png?resize=300%2C200 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1-1140x760.png 1140w" alt="Solarized theme for box plot" data-medium-file="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1-300x200.png?resize=300%2C200" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1-300x200.png?resize=300%2C200"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/boxplot_solarized/#main"><img sizes="(max-width: 300px) 100vw, 300px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized.png" data-orig-size="1800,1200" data-image-title="boxplot_solarized" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="586" srcset="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-300x200.png?resize=300%2C200 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1140x760.png 1140w" alt="Bar chart in &quot;solarized&quot;" data-medium-file="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-300x200.png?resize=300%2C200" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_solarized-300x200.png?resize=300%2C200"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/barplot_dust/#main"><img sizes="(max-width: 300px) 100vw, 300px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust.png" data-orig-size="1800,1200" data-image-title="barplot_dust" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="583" srcset="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-300x200.png?resize=300%2C200 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-1140x760.png 1140w" alt="&quot;Dust&quot; theme for bar chart" data-medium-file="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-300x200.png?resize=300%2C200" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/barplot_dust-300x200.png?resize=300%2C200"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/pointplot-dust/#main"><img sizes="(max-width: 300px) 100vw, 300px" data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust.png" data-orig-size="1800,1200" data-image-title="pointplot-dust" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="584" srcset="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-300x200.png?resize=300%2C200 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-1140x760.png 1140w" alt="Scatter diagram with &quot;dust&quot; theme." data-medium-file="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-300x200.png?resize=300%2C200" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot-dust-300x200.png?resize=300%2C200"></a></p>
<h2>Custom palettes with ggthemr</h2>
<p>If you’re in a working environment that has it’s own custom palette, for example a consultancy or accounting firm, it’s great to have ggplot2 figures match your document templates and power point files.</p>
<p>Ggthemr allows you to specify a custom theme palette that can be applied easily. Imagine we worked for “<a target="_blank" href="http://www.tableau.com/">Tableau</a>“, the data visualisation and business intelligence platform.</p>
<p>To define the custom theme, get the colour scheme for tableau figures in hex, choose a base theme, then define the swatch for ggthemr:</p>
<pre>tableau_colours &lt;- c('#1F77B4', '#FF7F0E', '#2CA02C', '#D62728', '#9467BD', '#8C564B', '#CFECF9', '#7F7F7F', '#BCBD22', '#17BECF')
# you have to add a colour at the start of your palette for outlining boxes, we'll use a grey:
tableau_colours &lt;- c(&quot;#555555&quot;, tableau_colours)
# remove previous effects:
ggthemr_reset()
# Define colours for your figures with define_palette
tableau &lt;- define_palette(
 swatch = tableau_colours, # colours for plotting points and bars
 gradient = c(lower = tableau_colours[1L], upper = tableau_colours[2L]), #upper and lower colours for continuous colours
 background = &quot;#EEEEEE&quot; #defining a grey-ish background 
)
# set the theme for your figures:
ggthemr(tableau)
# Create plots with familiar tableau look
point_plot
bar_plot
box_plot</pre>
<p><a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/barplot_tableau/#main"><img data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_tableau.png" data-orig-size="1800,1200" data-image-title="barplot_tableau" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="556" alt="Bar plot with Tableau colours" data-medium-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_tableau-300x200.png" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/barplot_tableau-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/barplot_tableau-150x150.png?resize=150%2C150"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/pointplot_tableau/#main"><img data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot_tableau.png" data-orig-size="1800,1200" data-image-title="Tableau themed point diagram using gather" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="559" alt="Scatter plot using ggthemr to define tableau colours" data-medium-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot_tableau-300x200.png" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/pointplot_tableau-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/pointplot_tableau-150x150.png?resize=150%2C150"></a><br>
<a target="_blank" href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/boxplot_tableau/#main"><img data-image-description="" data-orig-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_tableau.png" data-orig-size="1800,1200" data-image-title="box plot using tableau colours created in R" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="557" alt="Box plot with ggthemr created tableau palette." data-medium-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_tableau-300x200.png" data-large-file="http://www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_tableau-1024x683.png" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="http://i0.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/boxplot_tableau-150x150.png?resize=150%2C150"></a>
</p>
<p>Along with the swatch, gradient, and background elements of the figures, define_palette() also accepts specification of the figure text colours, line colours, and minor and major gridlines.</p>
<h2>Additional figure controls</h2>
<p>There are three additional controls in the ggthemr package allowing further figure adjustments:</p>
<ul>
<li>“Type” controls whether the background colour spills over the entire plot area, or just the axes section, options inner or outer</li>
<li>“Spacing” controls the padding between the axes and the axis labels / titles, options 0,1,2.</li>
<li>“Layout” controls the appearance and position of the axes and gridlines – options clean, clear, minimal, plain, scientific.</li>
</ul>
<p>For example, a new figure look can be created with:</p>
<pre>ggthemr(&quot;earth&quot;, type=&quot;outer&quot;, layout=&quot;scientific&quot;, spacing=2)
point_plot</pre>
<p>
<div class="wp-caption"><a target="_blank" href="http://i1.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/other_earth_options-1.png"><img sizes="(max-width: 450px) 100vw, 450px" srcset="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/other_earth_options-1-300x200.png?resize=450%2C300 300w, http://www.shanelynn.ie/wp-content/uploads/2016/07/other_earth_options-1-768x512.png 768w, http://www.shanelynn.ie/wp-content/uploads/2016/07/other_earth_options-1-1024x683.png 1024w, http://www.shanelynn.ie/wp-content/uploads/2016/07/other_earth_options-1-732x488.png 732w, http://www.shanelynn.ie/wp-content/uploads/2016/07/other_earth_options-1-1140x760.png 1140w" alt="other_earth_options.png" class="wp-image-616" src="http://i2.wp.com/www.shanelynn.ie/wp-content/uploads/2016/07/other_earth_options-1-300x200.png?resize=450%2C300" data-recalc-dims="1"></a>
<p class="wp-caption-text">“Earth” themed geom_point() with a scientific layout, extra spacing, and outer type specified for ggthemr.</p>
</div>
<h2>Manually customising a ggplot2 theme</h2>
<p>If ggthemr isn’t doing it for you, the in-built <a target="_blank" href="http://docs.ggplot2.org/current/theme.html">ggplot2 theming system</a> is completely customisable. There’s an extensive system in ggplot2 for changing every element of your plots – all defined using the theme() function. For example, the theme_grey() theme is defined as:</p>
<pre>theme_grey &lt;- function (base_size = 11, base_family = &quot;&quot;) 
{
 half_line &lt;- base_size/2
 theme(line = element_line(colour = &quot;black&quot;, size = 0.5, linetype = 1, 
 lineend = &quot;butt&quot;), rect = element_rect(fill = &quot;white&quot;, 
 colour = &quot;black&quot;, size = 0.5, linetype = 1), text = element_text(family = base_family, 
 face = &quot;plain&quot;, colour = &quot;black&quot;, size = base_size, lineheight = 0.9, 
 hjust = 0.5, vjust = 0.5, angle = 0, margin = margin(), 
 debug = FALSE), axis.line = element_line(), axis.line.x = element_blank(), 
 axis.line.y = element_blank(), axis.text = element_text(size = rel(0.8), 
 colour = &quot;grey30&quot;), axis.text.x = element_text(margin = margin(t = 0.8 * 
 half_line/2), vjust = 1), axis.text.y = element_text(margin = margin(r = 0.8 * 
 half_line/2), hjust = 1), axis.ticks = element_line(colour = &quot;grey20&quot;), 
 axis.ticks.length = unit(half_line/2, &quot;pt&quot;), axis.title.x = element_text(margin = margin(t = 0.8 * 
 half_line, b = 0.8 * half_line/2)), axis.title.y = element_text(angle = 90, 
 margin = margin(r = 0.8 * half_line, l = 0.8 * half_line/2)), 
 legend.background = element_rect(colour = NA), legend.margin = unit(0.2, 
 &quot;cm&quot;), legend.key = element_rect(fill = &quot;grey95&quot;, 
 colour = &quot;white&quot;), legend.key.size = unit(1.2, &quot;lines&quot;), 
 legend.key.height = NULL, legend.key.width = NULL, legend.text = element_text(size = rel(0.8)), 
 legend.text.align = NULL, legend.title = element_text(hjust = 0), 
 legend.title.align = NULL, legend.position = &quot;right&quot;, 
 legend.direction = NULL, legend.justification = &quot;center&quot;, 
 legend.box = NULL, panel.background = element_rect(fill = &quot;grey92&quot;, 
 colour = NA), panel.border = element_blank(), panel.grid.major = element_line(colour = &quot;white&quot;), 
 panel.grid.minor = element_line(colour = &quot;white&quot;, size = 0.25), 
 panel.margin = unit(half_line, &quot;pt&quot;), panel.margin.x = NULL, 
 panel.margin.y = NULL, panel.ontop = FALSE, strip.background = element_rect(fill = &quot;grey85&quot;, 
 colour = NA), strip.text = element_text(colour = &quot;grey10&quot;, 
 size = rel(0.8)), strip.text.x = element_text(margin = margin(t = half_line, 
 b = half_line)), strip.text.y = element_text(angle = -90, 
 margin = margin(l = half_line, r = half_line)), strip.switch.pad.grid = unit(0.1, 
 &quot;cm&quot;), strip.switch.pad.wrap = unit(0.1, &quot;cm&quot;), plot.background = element_rect(colour = &quot;white&quot;), 
 plot.title = element_text(size = rel(1.2), margin = margin(b = half_line * 
 1.2)), plot.margin = margin(half_line, half_line, 
 half_line, half_line), complete = TRUE)
}</pre>
<p>To create a theme of your own – you can change the values in this function definition, and add it to your plot as so:</p>
<pre>ggplot(...) + theme_your_own() # adding a theme to a figure</pre>
<p>As you can see, its not for the faint hearted, so for your quick-fix, I’d recommend looking at ggthemr and wish you the best with beautiful plots in your next presentation! Let us know how things go!</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-layout="box_count" data-send="true" data-height="62" data-href="http://www.r-bloggers.com/the-ggthemr-package-theme-and-colour-your-ggplot-figures/"></div></div><div><a data-url="http://www.r-bloggers.com/the-ggthemr-package-theme-and-colour-your-ggplot-figures/" data-counturl="http://www.r-bloggers.com/the-ggthemr-package-theme-and-colour-your-ggplot-figures/" data-count="vertical" data-text="The ggthemr package – Theme and colour your ggplot figures" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.shanelynn.ie/themes-and-colours-for-r-ggplots-with-ggthemr/"> R – Shane Lynn </a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/LiJ0Wdm6suk"></a></div>