Monday, July 31, 2006

[R graphics]: Multimodal surface

The R graphic is replicated from Figure 1 in Gill, Jeff, and George Casella. 2004. "Dynamic Tempered Transitions for Exploring Multimodal Posterior Distributions ." 12 (4): 425-43.

The R Graphic:




The R code:

target <- function(x,y){
abs(
(x*sin(20*y - 90) - y*cos(20*x + 45))^3
* acos(sin(90*y + 42)*x)
+ (x*cos(10*y + 10) - y*sin(10*x + 15))^2
* acos(cos(10*x + 24)*y)
)
}


x <- seq(-1,1,length=120)
y <- seq(-1,1,length=120)
z <- outer(x,y,target)

par(mar=c(0.2,0.2,0.2,0.2))
persp(x, y, z, theta=65, phi=15, box=F)

The usage of persp.

persp(x, ...)

## Default S3 method:
persp(x = seq(0, 1, len = nrow(z)), y = seq(0, 1, len = ncol(z)),
z, xlim = range(x), ylim = range(y),
zlim = range(z, na.rm = TRUE),
xlab = NULL, ylab = NULL, zlab = NULL, main = NULL, sub = NULL,
theta = 0, phi = 15, r = sqrt(3), d = 1, scale = TRUE, expand = 1,
col = "white", border = NULL, ltheta = -135, lphi = 0, shade = NA,
box = TRUE, axes = TRUE, nticks = 5, ticktype = "simple", ...)

theta is vertical rotation, phi is horizontal rotation.

No comments: