Re: [R] triangle contour plots

From: Cleber Borges <klebyn_at_yahoo.com.br>
Date: Wed, 20 Jun 2007 09:22:02 -0300

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.



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 20 Jun 2007 - 12:27:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Jun 2007 - 12:32:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.