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...@gmail.com
To: joeclar...@hotmail.com
CC: r-help@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                                       
______________________________________________
R-help@r-project.org 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.

Reply via email to