ggtern 2.0 now available

[This article was first published on ggtern: ternary diagrams in R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Recently ggplot2 received a severe makeover by releasing version 2.0, and in the spirit of improvement, I thought ggtern should also get an overhaul, so after a few-hundred hours of code review, here is what has changed:

Theme elements:

Previously, the nomenclature scheme for the new theme elements was a bit all over the shop, so the theme elements have been renamed. Every custom theme element for this package begins with ‘tern.XXX’ such as ‘tern.panel.background’ or ‘tern.axis.clockwise’, for the full list of new theme elements, see the help file:


Approved Geometries:

ggplot2 v2.0 has many new geometries, and not all of them are relevant to ggtern, so like before, this package has an opt-in policy where only certain geometries are approved:

geom_point, geom_path, geom_line, geom_label geom_text, geom_jitter, geom_polygon, geom_segment, geom_count and geom_blank.

New Geometries:

ggtern 2.0 carries over the existing geometries, and also ads a few more, the full list is as follows:

geom_Tline, geom_Rline, geom_Lline, geom_errorbarT, geom_errorbarL, geom_errorbarR, geom_density_tern, geom_confidence_tern, geom_mask, geom_smooth_tern, geom_Tisoprop, geom_Lisoprop, geom_Risoprop and geom_interpolate_tern

Stats and Positions:

The full list of approved stats are as follows:

stat_identity, stat_confidence, stat_density_tern, stat_smooth_tern, stat_sum, stat_unique, and stat_interpolate_tern
whilst the approved positions are as follows:
position_identity, position_nudge_tern and position_jitter_tern

Rebuilt Plot Arrangement Routine

The ggptern plot assembly routine has been completely re-written, the layout is much more predictable, one of the main achievements was providing the ability to rotate and shift the diagrams quite easily, here is an example:

arrangement = list()
for(r in seq(0,60,by=20)){
  x = ggtern(data=df,aes(Ab,An,Or)) +
    geom_point() + 
    theme_showarrows() + 
    theme_rotate(r) +
    ggtitle(sprintf("%i Degrees",r))
  arrangement[[length(arrangement) + 1]] = x
grid.arrange(grobs = arrangement)


Use of Orthonormal Basis

Several of the routines use isometric-logratio basis transformations, here is an example, using a new data-set included in the package, here we shall demonstrate the implementation of the new clipping mask, and two variants of the density estimate, the first applying density on the cartesian space, and the (now) default, isometric-logratio basis.

arrangement = list()
for(base in c('identity','ilr')){
  x = ggtern(Fragments,aes(Qm,Qp,M)) +
                        base=base,  ###NB Base Specification
                        colour='grey50') + 
      theme_dark() + geom_point() + 
      ggtitle(sprintf("Basis: %s",base)) +
      scale_fill_gradient(low='green',high='red') +
  arrangement[[length(arrangement) + 1]] = x
grid.arrange(grobs = arrangement,nrow=1)


Additional Labels

There are a few more labels and convenience functions which can be applied for additional customisation, here let us demonstrate the interpolation geometry, isolines, the automatic latex format parsing, the different labels for the precession arrows to the apex labels, and the legend positioning convenience function:

x = ggtern(Feldspar,aes(Ab,An,Or,value=T.C)) + 
                        aes(fill=..level..),expand=1) +
  theme_rgbw() + 
  theme_showarrows() + 
  theme_legend_position('topleft') + 
  labs(title  = "Elkins and Grove",
       fill   = "Temperature",
       Tarrow = "\textbf{Anorthite} CaAl_2Si_2O_8",
       Larrow = "\textbf{Albite} NaAlSi_3O_8",
       Rarrow = "\textbf{Orthoclase} KAlSi_3O_8") + 
  geom_point(aes(shape=Feldspar,colour=Feldspar)) + 
  geom_Tisoprop(value=0.5,colour='darkred') + 
  geom_Lisoprop(value=0.5,colour='darkblue') + 
  geom_Risoprop(value=0.5,colour='darkgreen') +


A Final Note

So the above is some of the new features, if you have any feedback, post a comment immediately below, the user manual can be found HERE. I probably spent a couple-of-hundred hours preparing this release, essentially re-writing the entire package to work with the new ggplot2 version, so, if this package makes your life easier and produces diagrams of publication quality, any kind of donation would be highly appreciated.

The post ggtern 2.0 now available appeared first on ggtern: ternary diagrams in R.

To leave a comment for the author, please follow the link and comment on their blog: ggtern: ternary diagrams in R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)