**ggtern: ternary diagrams in R**, and kindly contributed to R-bloggers)

For a long time, people have been sending me requests for a suitable smoothing / contouring / interpolation geometry be made available via ggtern, over and above the Kernel Density function. I am very pleased to say, that the recent version 1.0.6 has this feature added. Let me demonstrate how it works.

This geometry & stat required an additional mapping, to ‘value’, in order to conduct the interpolation, which by default is done using multivariate linear regression as the mechanism for the interpolation:

#Start by setting up the environment library(ggtern) data(Feldspar) theme_base <- function(){ list( theme_bw(), theme(legend.position = c(0,1), legend.justification = c(0,1))) } #Demonstrate the simplest example plot <- ggtern(Feldspar,aes(x=Or,y=An,z=Ab)) + geom_interpolate_tern(aes(value=P.Gpa,color=..level..)) + geom_point() + theme_base() + labs(color="P/Gpa Model") plot

There are plenty of options to tailor how the interpolation gets done, lets reduce the spacing between the contours, and add some more vibrant colours:

#Demonstrate the use of some options plot <- ggtern(Feldspar,aes(x=Or,y=An,z=Ab)) + geom_interpolate_tern(aes(value= P.Gpa,fill=..level..), colour = "white", formula = value~poly(x,y, degree=2, raw=TRUE), method = "lm", binwidth = 25, buffer = 1.5, n = 200) + geom_point() + theme_base() + scale_fill_gradient(low="green",high="red") + labs(fill="P/GPa Model") plot

For further information, see the help file, ?stat_interpolate_tern or ?geom_interpotate_tern

The post Ternary Interpolation / Smoothing appeared first on ggtern: ternary diagrams in R.

**leave a comment**for the author, please follow the link and comment on their blog:

**ggtern: ternary diagrams in R**.

R-bloggers.com 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...