Ternary Interpolation / Smoothing
This article is originally published at http://www.ggtern.com
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 following:
?stat_interpolate_tern ?geom_interpotate_tern
Thanks for visiting r-craft.org
This article is originally published at http://www.ggtern.com
Please visit source website for post related comments.