Colored contour plot / heat map

R
Author

Vinh Nguyen

Published

May 12, 2009

Example: Bivariate normal density (mean=(0,0), var-cov=diag(1,1))

```{r}
##R's heatmap function is NOT what i want 
##I want a simple colored contour plot / heat map 
library(mvtnorm) ##get multivariate normal functions 
x <- seq(-2,2,.01) 
X <- cbind(rep(x,each=length(x)), rep(x, length(x))) 
z <- matrix(dmvnorm(X), nrow=length(x)) 
filled.contour(x=x,y=x,z=z, nlevels=100) ##take in vector x and y with matrix z of values 

##See ?palettes for different color scheme 
filled.contour(x=x,y=x,z=z, nlevels=100, color.palette=topo.colors)
filled.contour(x=x,y=x,z=z, nlevels=100, color.palette=heat.colors) 
filled.contour(x=x,y=x,z=z, nlevels=100, color.palette=rainbow) 
filled.contour(x=x,y=x,z=z, nlevels=100, color.palette=terrain.colors) 
filled.contour(x=x,y=x,z=z, nlevels=100, color.palette=cm.colors)
##default 

jpeg("ColoredContourHeatMap-MVN.jpeg") 
filled.contour(x=x,y=x,z=z, nlevels=100, color.palette=terrain.colors) 
dev.off()
```