ms609 / Ternary

Create ternary plots in R

Home Page:https://ms609.github.io/Ternary/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I just want to be able to use the package for contour plots

daacosta opened this issue · comments

Dear all,

If my question is out of line I will understand. Years ago I found this function to do contour plots in ternary diagrams:

trimage <- function(f){
    x = y = seq( 1, 0, l=181 )
    t1 = length(x)
    im = aux = numeric(0)
    for( i in seq( 1, t1, by = 2 ) ){
            #idx = seq( t1**2, i*t1, by = -t1 ) - ((t1 - i):0)
            idx = seq( i*t1, t1**2, by = t1 ) - (i-1)
            im = c(im, aux, idx, aux )
            aux = c(aux, NA)
            }
    z =  outer(X=x, Y=y, FUN=f)
    return( matrix(z[im],nr=t1) )
}
#########################################################
# Example:
f = function(x1,x2){
    x3 = 1 - x1 - x2
    z = x1 + 0*x2 -x3 + 4*x1*x2 + 27*x1*x2*x3
    return( z )
    }
z = trimage( f )
par( xaxt='n', yaxt='n', bty='n', pty='s')
image( z, col=rainbow(256) )
contour( z, add=T )

OK? It works OK and I am happy with it except for the fact that I can´t see any axes in the plot and I was wondering if I could use your package to improve upon what I have... Bottom line is: I need to plot contour plots from equations of the form $f(X_A, X_B, X_C)=Z$ on a triangular diagram... Hopefully with the axes...

Many thanks for your attention to this matter.

Regards,

Diego

Hi Diego,

Thanks for the comment, this is a functionality I've pondered briefly in the past. As there is a use case for it, I'll see whether I can find time to implement this in some fashion in the package (though it may be a little while before I can get round to it).

Martin

This is now implemented in the development version of the package, which you can install with
devtools::install_github('ms609/Ternary'). Let me know how you get on with it, and if you have any suggestions I'll aim to implement them before submitting the revised package to CRAN in the next few weeks.