On 6/18/2007 8:12 AM, 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?
The usual contour function leaves blanks where you give it NA values, so you could put the f values into a rectangular array with NA outside the triangle and use that. I don't know how you're thinking of displaying things, but one possible transformation from (x,y) to (p1, p2, p3) would be f <- function(p1, p2, p3) p3 # just to illustrate maxy <- sin(pi/3) x <- seq(0,1,len=100) y <- seq(0, maxy, len=100) p1 <- outer(x,y, function(x,y) x - y/maxy/2) p2 <- outer(x,y, function(x,y) y/maxy) p3 <- 1-p1-p2 z <- ifelse(0 < p1 & 0 < p3, f(p1,p2,p3), NA) contour(x,y,z) This puts p1==1 at the bottom right, p2==1 at the top, and p3==1 at the bottom left. Duncan Murdoch > > Functions triplot(), triangle.plot(), and ternaryplot() give > only scatterplots, AFAICS > > > > > > -- > Robin Hankin > Uncertainty Analyst > National Oceanography Centre, Southampton > European Way, Southampton SO14 3ZH, UK > tel 023-8059-7743 > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.