[R] heatmap.2() yielding an inappropriate key?

2010-07-19 Thread Karl Brand

Esteemed R-users,

heatmap.2() is yielding an inappropriate key based on my colors and 
break-points.


In the reproducible example below, the key is inappropriate (to me) because-

1. 'Orange' is simply not represented in the key, despite its prescence 
in the heatmap.
2. The proportions of the key are clearly out, ie., my largest bin, (0.1 
- 0.2) is half the range, but this bin (colored gray) clearly extnds 
bellow the 0.1 tick mark of the key, beyond its specified bin.


What am i missing/doing wrong? Or for a key set up like this example is 
heatmap.2() unsuitable, necessitating production with another graphics 
functions? If so, recommendations appreciated. I have tried ggplot2, but 
struggle getting this function producing what i need. And i just need to 
make a nice key at this point.


All thoughts and suggestions greatly appreciated.
cheers,

karl


#reproducible example:
library(gplots)
set.seed(5)
mat - matrix(runif(50,  min=0, max=0.2), nrow = 10, ncol = 5)
heatmap.2(mat,
  Rowv=NULL, Colv=NULL,
  col = c(heat.colors(4, alpha = 1), gray),
  breaks = c(0, 0.01, 0.05, 0.075, 0.1, 1),
  trace = none,
  dendrogram = none,
  density.info = none,
  margins=c(12, 8))

--
Karl Brand k.br...@erasmusmc.nl
Department of Genetics
Erasmus MC
Dr Molewaterplein 50
3015 GE Rotterdam
P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268

__
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.


Re: [R] heatmap.2() yielding an inappropriate key?

2010-07-19 Thread Karl Brand

I see now my error, several in fact:

The 'breaks' specified need to be of a similar range to the data range, 
and they should be equally spaced.


So in my example:

breaks = seq(0, 0.2, 0.001)

If one needs uneqaully spaced coloring, as i do, then this is achieved 
by specifying the approprate color per bin, and repeating the same color 
as needed. Script below achives my goal. But if anyone has a simpler 
method they'd care to share- would be v. happy to receive!


karl

#achives my goal
library(gplots)
BRKS - seq(0, 0.2, 0.001)
COLS - c(rep(heat.colors(4)[1], 10),   # 0.00-0.01 bin  (10 bins)
  rep(heat.colors(4)[2], 40),   # 0.01-0.05 'bin' (40 bins)
  rep(heat.colors(4)[3], 25),   # 0.05-0.075 'bin' (25 bins)
  rep(heat.colors(4)[4], 25),   # 0.075-0.1 'bin' (25 bins)
  rep(gray, (length(BRKS)-100)-1))# 0.10-1.0 'bin' (100 bins)
set.seed(5)
mat - matrix(runif(50,  min=0, max=0.2), nrow = 10, ncol = 5)
heatmap.2(mat,
  Rowv=NULL, Colv=NULL,
  col = COLS,
  breaks = BRKS,
  trace = none,
  dendrogram = none,
  density.info = none,
  margins=c(12, 8))






On 7/19/2010 12:42 PM, Karl Brand wrote:

Esteemed R-users,

heatmap.2() is yielding an inappropriate key based on my colors and
break-points.

In the reproducible example below, the key is inappropriate (to me)
because-

1. 'Orange' is simply not represented in the key, despite its prescence
in the heatmap.
2. The proportions of the key are clearly out, ie., my largest bin, (0.1
- 0.2) is half the range, but this bin (colored gray) clearly extnds
bellow the 0.1 tick mark of the key, beyond its specified bin.

What am i missing/doing wrong? Or for a key set up like this example is
heatmap.2() unsuitable, necessitating production with another graphics
functions? If so, recommendations appreciated. I have tried ggplot2, but
struggle getting this function producing what i need. And i just need to
make a nice key at this point.

All thoughts and suggestions greatly appreciated.
cheers,

karl


#reproducible example:
library(gplots)
set.seed(5)
mat - matrix(runif(50, min=0, max=0.2), nrow = 10, ncol = 5)
heatmap.2(mat,
Rowv=NULL, Colv=NULL,
col = c(heat.colors(4, alpha = 1), gray),
breaks = c(0, 0.01, 0.05, 0.075, 0.1, 1),
trace = none,
dendrogram = none,
density.info = none,
margins=c(12, 8))



--
Karl Brand k.br...@erasmusmc.nl
Department of Genetics
Erasmus MC
Dr Molewaterplein 50
3015 GE Rotterdam
P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268

__
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.