Ternary Interpolation / Smoothing

[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.

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

unnamed-chunk-2-1

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

unnamed-chunk-3-1

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.

To 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 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)