Skip to content
Prev 180127 / 398506 Next

Response surface plot

hello,

I have an code for similar plot in 2D.

HTH

Cleber Borges
------------------------------------------------------
#########################################################
#########################################################
#########################################################

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

ternary_func <- function(x1, x2) {
x3=1-x1-x2
-100*x1 + 0*x2 + 100*x3 + 200*x1*x2
}

zmat1 <- trimage(ternary_func)

windows(w=4.5, h=4.5, restoreConsole = TRUE )
par(mar=c(5,5,5,5), pty='s', xaxt='n', yaxt='n', bty='n' )
image(z=zmat1, ylab='', xlab='' )
contour(z=zmat1, add=T, nlevels=10 )


### tips.: use tim.colors in package 'fields'

library(fields)

windows(w=4.5, h=4.5, restoreConsole = TRUE )
par(mar=c(5,5,5,5), pty='s', xaxt='n', yaxt='n', bty='n' )
image(z=zmat1, ylab='', xlab='', col=tim.colors(256) )
contour(z=zmat1, add=T, nlevels=10 )


#########################################################
#########################################################
#########################################################
------------------------------------------------------
Tim Carnus escreveu: