<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/version-2-2-1-released/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.ggtern.com/2017/07/23/version-2-2-1-released/"> ggtern: ternary diagrams in R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>It has been a while since any kind of significant update has been released for the ggetern library, and the other day a minor update was submitted to CRAN, which is now available. There were a few minor bug fixes, and the inclusion of a few new geometries which some of you may find of value.</p>
<h3>Newly Approved Geometry: geom_encircle </h3>
<p>One of our users commented on the ggtern blog, that the geom_encircle geometry provided by the <a rel="nofollow" href="https://cran.rstudio.com/web/packages/ggalt/index.html" target="_blank">ggalt</a> package might be handy, and after some investigation, this didn’t need any kind of modification, so it has been added to the list of approved protos, and can be used as follows:</p>

<pre>library(ggtern)
library(ggalt)     #&lt; Install this if it isn't installed!
data(&quot;Fragments&quot;)
base = ggtern(Fragments,aes(Qm,Qp,Rf+M,fill=GrainSize,shape=GrainSize)) + 
  theme_bw() + 
  theme_legend_position('tr') + 
  geom_encircle(alpha=0.5,size=1) + 
  geom_point() +
  labs(title    = &quot;Example Plot&quot;,
       subtitle = &quot;using geom_encircle&quot;)
print(base)</pre>

<p>Pretty simple huh, well this produces the following output:</p>
<p><a rel="nofollow" href="https://i2.wp.com/www.ggtern.com/wp-content/uploads/2017/07/geom_encircle.png" target="_blank"><img sizes="(max-width: 554px) 100vw, 554px" src="https://i2.wp.com/www.ggtern.com/wp-content/uploads/2017/07/geom_encircle.png?w=450" alt="" class="wp-image-2431" data-recalc-dims="1"></a></p>
<p>As you can see (and as expected), points have been circled in an ‘approximate’ manner, sort of like someone grabbing a pen and circling on a piece of paper, perfect for highlighting features without any sort of statistical significance. Of course you will need to install the <a rel="nofollow" href="https://cran.rstudio.com/web/packages/ggalt/index.html" target="_blank">ggalt</a> package, if it is not already installed.</p>
<h3>New Text/Label Geometries:</h3>
<p>Some other feedback was generously offered, in that it might be convenient if users could apply text or label elements to the plot region, by defining a fractional position in x or y, relative to the viewport, and so, this has been taken this on board and created two new geometries geom_text_viewport and and geom_label_viewport — these are basically the same as the geom_text and geom_label geometries, except, the user is only expected to provide an x and y positional mapping, which are values constrained between the limits [0,1], representing fractional coordinates of the plot viewport, used as follows:</p>

<pre>df.vp = data.frame(x     = c(.5,1,0,0,1),
                   y     = c(.5,1,0,1,0),
                   label = c('Middle','Top Right','Bottom Left','Top Left','Bottom Right'))
base2 = base + 
  theme(legend.position = 'right') + 
  geom_mask() + 
  geom_text_viewport(data=df.vp,aes(x=x,y=y,label=label,color=label),inherit.aes = FALSE) +
  labs(color    = &quot;Label&quot;,
       subtitle = &quot;using geom_text_viewport&quot;)
print(base2)</pre>

<p><a rel="nofollow" href="https://i2.wp.com/www.ggtern.com/wp-content/uploads/2017/07/geom_text_viewport.png" target="_blank"><img sizes="(max-width: 554px) 100vw, 554px" src="https://i2.wp.com/www.ggtern.com/wp-content/uploads/2017/07/geom_text_viewport.png?w=450" alt="" class="wp-image-2434" data-recalc-dims="1"></a></p>

<pre>base3 = base + 
  theme(legend.position = 'right') + 
  geom_mask() + 
  geom_label_viewport(data=df.vp,aes(x=x,y=y,label=label,color=label),inherit.aes = FALSE) +
  labs(color    = &quot;Label&quot;,
       subtitle = &quot;using geom_label_viewport&quot;)
print(base3)</pre>

<p><a rel="nofollow" href="https://i2.wp.com/www.ggtern.com/wp-content/uploads/2017/07/geom_label_viewport.png" target="_blank"><img sizes="(max-width: 554px) 100vw, 554px" src="https://i2.wp.com/www.ggtern.com/wp-content/uploads/2017/07/geom_label_viewport.png?w=450" alt="" class="wp-image-2435" data-recalc-dims="1"></a></p>
<p>The above have the special added benefit with respect to ternary diagrams, insomuch as they reduce the mental overhead of having to think in ternary coordinates, if you want to manually place a label somewhere. Furthermore, both of these new geometries behave similarly on native ggplot2 objects, so, these represent an intuitive way to place labels in a relative manner to the plot region, without having to consider the axis limits.</p>
<p>Finally, many of you have been citing ggtern in the literature, which I am grateful for, please continue to do so, and let me know so that I might add your respective publications to the <a rel="nofollow" href="http://www.ggtern.com/publications/" target="_blank">publications ledger.</a></p>
<p>I have been thinking alot of the best way to enable piper diagrams, and/or diagrams with cartesian-binary plots perpendicular to the ternary axes, I am hoping to get this functionality happening soon, which will considerably improve the depth of outputs that this package is able to produce.</p>
<p>Some of you have contacted me to produce custom geometries for your respective projects, and as a final plug, this is something I am more than happy to do…</p>
<p>Cheerio,</p>
<p>NH</p>
<p>The post <a rel="nofollow" href="http://www.ggtern.com/2017/07/23/version-2-2-1-released/" target="_blank">Version 2.2.1 Released</a> appeared first on <a rel="nofollow" href="http://www.ggtern.com/" target="_blank">ggtern: ternary diagrams in R</a>.</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="http://www.ggtern.com/2017/07/23/version-2-2-1-released/"> ggtern: ternary diagrams in R</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 width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/qLXsxuai36U" height="1"></a></div>