[R] triangle contour plots

Cleber Borges klebyn at yahoo.com.br
Wed Jun 20 14:22:02 CEST 2007


Hi,
I used similar things to Chemical Mixture Modelling. ( Scheffe model)
I make the function below.

Cleber
+++++++++++++++++++++++++++++++++

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 )




Robin Hankin wrote:
> Suppose I have three numbers p1, p2, p3 with
> 0 <= p1,p2,p3 <= 1  and p1+p2+p3=1,
> and a  function  f=f(p1,p2,p3)   =  f(p1,p2,1-p1-p2).
>
> How to draw a contour plot of f() on the p1+p2+p3=1 plane,
> that is, an equilateral triangle?
>
> Functions triplot(), triangle.plot(), and ternaryplot()  give
> only  scatterplots, AFAICS
>   




		
_______________________________________________________ 

Experimente já e veja as novidades.



More information about the R-help mailing list