Re: [R] Help with filled.contour()

From: Dieter Menne <dieter.menne_at_menne-biomed.de>
Date: Mon 01 Jan 2007 - 19:13:07 GMT

Michael Kubovy <kubovy <at> virginia.edu> writes:

>
> The following plot is a first approximation to what I need:
.. see below

> ***********************************
> It has four drawbacks. I would like:
> (1) to remove the white grid;
> (2) to remove the white contours;
> (3) its appearance to be smooth;
> (4) to remove the key.

In partial fulfillment of your requirements, increasing the levels gives a nice smooth plot.

mu1 <- 0
mu2 <- 5

s <- 1
x <- seq(-2.5, 7.5, length = 41)
y <- seq(-2.5, 2.5, length = 41)
f <- function(x,y){
term1 <- 1/(2*pi*sqrt(s*s))
term2 <- -1/2
term3 <- (x - mu1)^2/s

term4 <- (y - mu1)^2/s
term5 <- (x - mu2)^2/s
term1*(.5 * exp(term2*(term3 + term4)) + .5 * exp(term2*(term5 + term4)))
}

z <- outer(x, y, f)
persp(x, y, z)
require(grDevices)
filled.contour(x, y, z, axes = F, frame.plot = F, asp = 1,

     col = palette(gray(seq(0, 0.9, len = 500))), nlevels = 500)

I thought that lattice would be more flexible, and getting rid of the keys was easy, only I could not get the smooth plot. Deepayan, are we missing something?

library(lattice)
dt <- expand.grid(x=x,y=y)
dt$z <- apply(dt, 1,function(xy) f(xy[1],xy[2])) col.regions = palette(gray(seq(0, 0.9, len = 500))) contourplot(z~x*y,data=dt,cuts=20,col.regions=col.regions,colorkey=FALSE,   contour=TRUE,region=TRUE)

Dieter



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. Received on Tue Jan 02 09:01:41 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 02 Jan 2007 - 07:30:24 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.