New Geometry – Ternary Errorbars

February 2, 2014

(This article was first published on ggtern: ternary diagrams in R, and kindly contributed to R-bloggers)

ggtern has introduced a new series of geometries to represent known errors in data, they are relatively easy to use and are along the lines of the geom_errorbar(...) and geom_errorbarh(...) geometries in ggplot2.

Analagous the errorbars in ggplot2, in ggtern, the new geometries [and additional required mappings] are thus listed as follows:

  • geom_errorbarT(…) [Tmin, Tmax]
  • geom_errorbarL(…) [Lmin, Lmax]
  • geom_errorbarR(…) [Rmin, Rmax]

These three geometries represent errors relative to the Top, Left and Right apex species, respectively.

Example of Ternary Errorbar Usage

To start with, let us prepare some data:

# Load the data
IX = c('Ab', 'An', 'Or')
#Error bar width
width <- 0.01
#Create error data +- 5%
for (ix in IX) {
  Feldspar[, paste0(ix, '_min')] = pmax(Feldspar[, ix] - 5, 0)
  Feldspar[, paste0(ix, '_max')] = pmin(Feldspar[, ix] + 5, 100)
mytitle <- function(x){
  ggtitle(paste('Demonstration of: geom_errorbar',x,'(...)',sep=""))
# Set the theme for subsequent plots

Top species error bars can be produced with the following:

ggtern(data = Feldspar, aes(x = Ab, y = An, z = Or)) + 
  geom_errorbarT(aes(Tmin = An_min, Tmax = An_max, width = width), 
                 color = 'darkred') + 
  geom_point() + mytitle("T")

plot of chunk unnamed-chunk-3

Left species error bars can be produced in exactly the same manner:

ggtern(data = Feldspar, aes(x = Ab, y = An, z = Or)) + 
  geom_errorbarL(aes(Lmin = Ab_min, Lmax = Ab_max, width = width), 
                 color = 'darkblue') + 
  geom_point() + mytitle("L")

plot of chunk unnamed-chunk-4

Right species error bars, you guessed it, same again:

ggtern(data = Feldspar, aes(x = Ab, y = An, z = Or)) + 
  geom_errorbarR(aes(Rmin = Or_min, Rmax = Or_max, width = width), 
                 color = 'darkgreen') + 
  geom_point() + mytitle("R")

plot of chunk unnamed-chunk-5


The post New Geometry – Ternary Errorbars 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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


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)