Heat Maps

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Heat Maps

Akhil dua
Hello Everyone I am new to R


I have drawn indifference curves using the program below (Contour Plot)


u <- function(x, y) x^0.5 + y^0.5
x <- seq(0, 1000, by=1)
y <- seq(0, 1000, by=1)
a <- c(10, 20, 30)
contour(x, y, outer(x, y, u),levels=a,col="blue")




Now can any body please tell me how to draw Heat maps

and that too on the same indifference curve plot (contour)

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Heat Maps

Joseph Clark

the "image" function should do it, something like this: image( x, y, outer(x,y,u), col=[some vector of colors] ) You can add a "breaks" parameter but you need one more break than you have colors (include the start and end point).  Or just let it be automatic.I have used colorpanel() from the gplots library to generate graduated color shades.  This is based on actual code I'm using for one of my heatmaps: library(gplots) # for colorpanelz <- outer(x,y,u)image( x, y, z, colorpanel(10,"steelblue","white"), breaks=quantile(z,seq(0,1,by=0.1))  )box() # for appearancespar(new=TRUE)  # you want the lines on top of the colors, so do the contour plot secondcontour(...) It will produce ten colors with steelblue for the highest value and white for the lowest value, and one shade for each decile.  You can omit the "breaks" term.  > I have drawn indifference curves using the program below (Contour Plot)

>
>
> u <- function(x, y) x^0.5 + y^0.5
> x <- seq(0, 1000, by=1)
> y <- seq(0, 1000, by=1)
> a <- c(10, 20, 30)
> contour(x, y, outer(x, y, u),levels=a,col="blue")
>
>
>
>
> Now can any body please tell me how to draw Heat maps
>
> and that too on the same indifference curve plot (contour)
>
       
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Heat Maps

Akhil dua
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

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Heat Maps

David Carlson
Something like this?

> image(x, y, outer(x, y, u), breaks=c(0, a), col=heat.colors(3))
> contour(x, y, outer(x, y, u),levels=a, col="blue", add=TRUE)

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Akhil dua
> Sent: Monday, July 02, 2012 2:26 AM
> To: Joseph Clark
> Cc: [hidden email]
> Subject: Re: [R] Heat Maps
>
> 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
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Heat Maps

Joseph Clark
In reply to this post by Akhil dua

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: [hidden email]
To: [hidden email]
CC: [hidden email]

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    
______________________________________________
[hidden email] 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.