Super Nerdy Cool

My (technical) adventures through the professional world…
May 12, 2009

Colored contour plot / heat map

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

<pre class="src src-R"><span style="color: #ff4500;">##</span><span style="color: #ff4500;">R's heatmap function is NOT what i want </span>

##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()

http://blog.nguyenvq.com/wp-content/uploads/2009/05/ColoredContourHeatMap-MVN.jpeg

Leave a Comment