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

From: Jeffrey Horner <jeff.horner_at_vanderbilt.edu>
Date: Wed 03 Jan 2007 - 22:09:32 GMT

Dieter Menne wrote:

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

>> I tried and it gave a strange result. See
>> http://people.virginia.edu/~mk9y/mySite/twoGaussian.R
>> and
>> http://people.virginia.edu/~mk9y/mySite/twoGaussian.pdf
>>
>> *********************************
>> Session Info
>> *********************************
>> > sessionInfo()
>> R version 2.4.1 (2006-12-18)
>> powerpc-apple-darwin8.8.0
> 
> Hmm, strange, I can reproduce your problem on Windows (otherwise same config)
> with pdf, but it looks beautifully on screen for me if I mentally remove the
> ugly legend.


Try the image function. The smoothness of the plot will be proportional to the length of x and y. For instance 200 isn't bad:

mu1 <- 0
mu2 <- 5

s <- 1
x <- seq(-2.5, 7.5, length = 200)
y <- seq(-2.5, 2.5, length = 200)
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)))
} # setting up the function of the multivariate normal density z <- outer(x, y, f)
# persp(x, y, z)
require(grDevices)
#pdf('twoGaussian.pdf')
#filled.contour(x, y, z, axes = F, frame.plot = F, asp = 1,
#               col = gray(seq(0, 0.9, len = 25)), nlevels = 25)
image(x,y,z,col=gray(seq(0,0.9,len=200)))

Cheers,

Jeff

-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner

______________________________________________
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 Thu Jan 04 11:46:35 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 Thu 04 Jan 2007 - 01:30:28 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.