<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/the-yarrr-package-0-0-8-is-finally-on-cran/"></div></div><div><a data-url="https://www.r-bloggers.com/the-yarrr-package-0-0-8-is-finally-on-cran/" data-counturl="https://www.r-bloggers.com/the-yarrr-package-0-0-8-is-finally-on-cran/" data-count="horizontal" data-text="The yarrr package (0.0.8) is (finally!) on CRAN" 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://nathanieldphillips.com/2016/10/the-yarrr-package-is-now-on-cran/"> R – Nathaniel D. Phillips, PhD</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Great news R pirates! The yarrr package, which contains the pirateplot, has now been updated to version 0.0.8 and is up on CRAN (after hiding in plain sight on GitHub). Let’s install the latest version (0.0.8) and go over some of the updates:</p>
<pre>
install.packages(&quot;yarrr&quot;)  # Install package from CRAN
library(&quot;yarrr&quot;) # Load the package!
</pre>
<p>The most important function in the yarrr package is pirateplot(). What the heck is a pirateplot? A pirateplot is a modern way of visualising the relationship between a categorical independent variable, and a continuous dependent variable. Unlike traditional plotting methods, like barplots and boxplots, a pirateplot is an RDI plotting trifecta which presents Raw data (all data as points), Descriptive statistics (as a horizontal line at the mean — or any other function you wish), and Inferential statistics (95% Bayesian Highest Density Intervals, and smoothed densities).</p>
<p><a target="_blank" href="https://i1.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/pirateplot-elements.png"><img sizes="(max-width: 610px) 100vw, 610px" alt="pirateplot-elements" class="wp-image-809" src="https://i1.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/pirateplot-elements.png?resize=456%2C341" data-recalc-dims="1"></a></p>
<p>For a full guide to the package, check out the package guide at CRAN <a target="_blank" href="https://cran.r-project.org/web/packages/yarrr/vignettes/guide.html">here</a>. For now, here are some examples of pirateplots showing off some the package updates.</p>
<h2>Up to 3 IVs</h2>
<p>You can now include up to three independent variables in your pirateplot. The first IV is presented as adjacent beans, the second is presented in different groups of beans in the same plot, and the third IV is shown in separate plots.</p>
<p>Here is a pirateplot of the heights of pirates based on three separate IVs: headband (whether the pirate wears a headband or not), sex, and eyepatch (whether the pirate wears an eye patch or not):</p>
<pre>
pirateplot(formula = height ~ sex + headband + eyepatch,
           point.o = .1,
           data = pirates)
</pre>
<p><a target="_blank" href="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/threeivpp-1.png"><img sizes="(max-width: 891px) 100vw, 891px" alt="threeivpp" class="wp-image-810" src="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/threeivpp-1.png?resize=456%2C265" data-recalc-dims="1"></a></p>
<p>Here, we can see that male pirates tend to be the tallest, but there there doesn’t seem to be a difference between those who wear headbands or not, and those who have eye patches or not.</p>
<h2>New color palettes</h2>
<p>The updated package has a few fun new color palettes contained in the piratepal() function. The first, called ‘xmen’, is inspired by my 90s Saturday morning cartoon nostalgia. </p>
<pre>
# Display the xmen palette
piratepal(palette = &quot;xmen&quot;, 
          trans = .1, # Slightly transparent colors
          plot.result = TRUE)
</pre>
<p><a target="_blank" href="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/xmen_display-1.png"><img sizes="(max-width: 567px) 100vw, 567px" alt="xmen_display" class="wp-image-805" src="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/xmen_display-1.png?resize=456%2C401" data-recalc-dims="1"></a></p>
<p>Here, I’ll use the xmen palette to plot the distribution of the weights of chickens over time (if someone has a more suitable dataset for the xmen palette let me know!):</p>
<pre>
pirateplot(formula = weight ~ Time, 
           data = ChickWeight, 
           main = &quot;Weights of chickens by Time&quot;,
           pal = &quot;xmen&quot;, 
           gl.col = &quot;gray&quot;)

mtext(text = &quot;Using the xmen palette!&quot;, 
      side = 3, 
      font = 3)

mtext(text = &quot;*The mean and variance of chicken\nweights tend to increase over time.&quot;, 
      side = 1, 
      adj = 1,
      line = 3.5,
      font = 3,
      cex = .7)
</pre>
<p><a target="_blank" href="https://i0.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/xmen_chikens.png"><img sizes="(max-width: 567px) 100vw, 567px" alt="xmen_chikens" class="wp-image-806" src="https://i0.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/xmen_chikens.png?resize=456%2C401" data-recalc-dims="1"></a></p>
<p>The second palette called “pony” is inspired by the Bronys in our IT department.</p>
<pre>
# Display the pony palette
piratepal(palette = &quot;pony&quot;, 
          trans = .1, # Slightly transparent colors
          plot.result = TRUE)
</pre>
<p><a target="_blank" href="https://i0.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/pony_image.png"><img sizes="(max-width: 567px) 100vw, 567px" alt="pony_image" class="wp-image-807" src="https://i0.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/pony_image.png?resize=456%2C401" data-recalc-dims="1"></a></p>
<p>Here, I’ll plot the distribution of the lengths of movies as a function of their MPAA ratings (where G is for suitable for children, and R is suitable for adults)</p>
<pre>
pirateplot(formula= time ~ rating, 
           data = subset(movies, time > 0 &amp; rating %in% c(&quot;G&quot;, &quot;PG&quot;, &quot;PG-13&quot;, &quot;R&quot;)), 
           pal = &quot;pony&quot;, 
           point.o = .05, 
           bean.o = 1, 
           main = &quot;Movie times by rating&quot;, 
           bean.lwd = 2, 
           gl.col = &quot;gray&quot;)

mtext(text = &quot;Using the pony palette!&quot;, 
      side = 3, 
      font = 3)

mtext(text = &quot;*Movies rated for children\n(G and PG) tend to be longer \nthan those rated for adults&quot;, 
      side = 1, 
      adj = 1,
      font = 3,
      line = 3.5,
      cex = .7)
</pre>
<p><a target="_blank" href="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/pony_times.png"><img sizes="(max-width: 567px) 100vw, 567px" alt="pony_times" class="wp-image-808" src="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/pony_times.png?resize=456%2C401" data-recalc-dims="1"></a></p>
<p>To see all of the palettes (including those inspired by movies and a transit map of Basel), just run the function with “all” as the main argument</p>
<pre>
piratepal(palette = &quot;all&quot;)
</pre>
<p>Of course, if you find that these color palettes give you a headache, you can always set the plot to grayscale (or any other color), by specifying a single color in the palette argument. Here, I’ll create a grayscale pirateplot showing the distribution of movie budgets by their creative type:</p>
<pre>
pirateplot(formula = budget ~ creative.type, 
           data = subset(movies, budget > 0 &amp; 
                         creative.type %in% c(&quot;Multiple Creative Types&quot;, &quot;Factual&quot;) == FALSE),
           point.o = .02,
           xlab = &quot;Movie Creative Type&quot;,
           main = &quot;Movie budgets (in millions) by rating&quot;,
           gl.col = &quot;gray&quot;,
           pal = &quot;black&quot;)

mtext(&quot;Using a grayscale pirateplot&quot;, 
      side = 3, 
      font = 3)

mtext(&quot;*Superhero movies tend to have the highest budgets\n...by far!&quot;, 
      side = 1, adj = 1, line = 3, 
      cex = .8, font = 3)
</pre>
<p><a target="_blank" href="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/moviebudgetpp.png"><img sizes="(max-width: 1110px) 100vw, 1110px" alt="moviebudgetpp" class="wp-image-811" src="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/10/moviebudgetpp.png?resize=456%2C213" data-recalc-dims="1"></a></p>
<p>Looks like super hero movies have the highest budgets…by far!</p>
<h2>Acknowledgements and Comments</h2>
<p>– The pirateplot is largely inspired by the great beanplot package (<a href="https://cran.r-project.org/web/packages/beanplot/index.html">beanplot package link</a>) by Peter Kampstra.<br>
– Bayesian 95% HDIs are calculated using the truly amazing BayesFactor package (<a href="https://cran.r-project.org/web/packages/BayesFactor/index.html">BayesFactor package link)</a> by Brian Morey<br>
– The latest developer version of yarrr is always available at <a href="https://github.com/ndphillips/yarrr">https://github.com/ndphillips/yarrr</a>. Please post any bugs, issues, or feature requests at <a href="https://github.com/ndphillips/yarrr/issues">https://github.com/ndphillips/yarrr/issues</a></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/the-yarrr-package-0-0-8-is-finally-on-cran/"></div></div><div><a data-url="https://www.r-bloggers.com/the-yarrr-package-0-0-8-is-finally-on-cran/" data-counturl="https://www.r-bloggers.com/the-yarrr-package-0-0-8-is-finally-on-cran/" data-count="vertical" data-text="The yarrr package (0.0.8) is (finally!) on CRAN" 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://nathanieldphillips.com/2016/10/the-yarrr-package-is-now-on-cran/"> R – Nathaniel D. Phillips, PhD</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/TFp92rtG0fE"></a></div>