[R] Heat Maps

Joseph Clark joeclark77 at hotmail.com
Mon Jul 2 20:41:18 CEST 2012


u <- function(x, y) x^0.5 + y^0.5
x <- seq(0, 1000, by=1)
y <- seq(0, 1000, by=1)
z <- outer(x,y,u)
a <- c(10, 20, 30)
image(x,y,z)
par(new=TRUE)
contour(x,y,z,levels=a,xaxs="i",yaxs="i")

You need xaxs="i",yaxs="i" because image() and contour() treat the axes differently by default.


In my opinion, the plot would be prettier if you align the contour "levels" with the heatmap "breaks".
This would be the entire code:


u <- function(x, y) x^0.5 + y^0.5
x <- seq(0, 1000, by=1)
y <- seq(0, 1000, by=1)
z <- outer(x,y,u)
a <- ceiling(quantile(z,seq(0,1,0.1)))
image(x,y,z,col=heat.colors(10),breaks=a)
par(new=TRUE)
contour(x,y,z,levels=a[2:10],xaxs="i",yaxs="i")

This works without any special packages installed.
 

// joseph w. clark , phd candidate
\\ usc marshall school of business




Date: Mon, 2 Jul 2012 12:55:44 +0530
Subject: Re: [R] Heat Maps
From: akhil.dua.12 at gmail.com
To: joeclark77 at hotmail.com
CC: r-help at r-project.org

Thanks Joseph



but see i am not able to get heat maps with this code \
can u please give me the full codes to generate heat map on the same graph where i have drawn contour lines 		 	   		  


More information about the R-help mailing list