Ternary Interpolation / Smoothing

August 3, 2015

(This article was first published on 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
theme_base <-  function(){
    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")


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,
                        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")


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


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)