Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a ternary plot

Tags:

r

ggplot2

I want to plot the projection of 3-dimensional data on their simplex using ggplot2. I thought I could manage the transformation on cartesian coordinates using coord_trans(), but do not know how to do it exactly.

This is what I tried:

simplex.y  <- function( x1, x2, x3 ) {
  return( sqrt(0.75) *  x3 / (x1+x2+x3) )
} 
simplex.x  <- function( x1, x2, x3 ) {
  return( (x2 + 0.5 * x3) / (x1+x2+x3) )
}

x  <- data.frame(
  x1 = c( 0, 0, 1, 0.1, 0.6, 0.2 ),
  x2 = c( 0, 1, 0, 0.3, 0.2, 0.8 ),
  x3 = c( 1, 0, 0, 0.6, 0.2, 0.0 )
)

require(ggplot2)
ggplot( data = x, aes( x = c(x1, x2, x3), y = c(x1, x2, x3)) ) +
  geom_point() +
  coord_trans( x="simplex.x", y="simplex.y" )

Any suggestions are appreciated. Many thanks!

like image 610
Beasterfield Avatar asked May 03 '12 20:05

Beasterfield


People also ask

Can you make ternary plot in Excel?

Tri-plot is a Microsoft® Excel spreadsheet for the preparation of triangular (ternary) diagrams for particle-shape and tri-variate data. Conventional triangular diagrams are used to represent tri-variate data in which the three variables represent proportions of a whole (Fig. 1).

What does a ternary plot show?

Ternary diagrams represent three-component systems and are conveniently presented as triangular diagrams where each side corresponds to an individual binary system. However, in three dimensions the diagram is more complex with surfaces emerging (Fig. 3.5A) rather than lines as in the binary system.


1 Answers

The R package Ternary produces ternary plots from matrices and data.frames using the standard graphics functions.

Ternary plot created with R package Ternary

The above plot is created with:

x  <- data.frame(
  x1 = c( 0, 0, 1, 0.1, 0.6, 0.2 ),
  x2 = c( 0, 1, 0, 0.3, 0.2, 0.8 ),
  x3 = c( 1, 0, 0, 0.6, 0.2, 0.0 )
)
TernaryPlot()
TernaryPoints(x, col='red')
like image 154
Martin Smith Avatar answered Oct 15 '22 12:10

Martin Smith