Question: question about drawing heatmap with R
0
gravatar for biolab
5.1 years ago by
biolab1.1k
biolab1.1k wrote:

Dear all

I have a simple question about R drawing heatmap. I produced a heatmap using the following code, however, I want to swap the colors between yellow and red (i.e., by default yellow represent high value while red represent low values, i want to swap them). 

My second question is: how to add white lines for the boundaries of each unit ?  THANKS a lot!

n1 <- read.table(file="test.txt", header=T)
n1 <- data.matrix(n1)
heatmap.2(n1, trace="none",col=heat.colors(256))

 

heatmap R • 3.5k views
ADD COMMENTlink modified 5.1 years ago by arno.guille400 • written 5.1 years ago by biolab1.1k
1

I don't understand your second question but for your first question simply use

n1 <- read.table(file="test.txt", header=T)
n1 <- data.matrix(n1)
heatmap.2(n1, trace="none",col=rev(heat.colors(256)))
ADD REPLYlink modified 5.1 years ago • written 5.1 years ago by Irsan7.0k
1

If you are using heatmap.2, then I think you use rowsep and/or colsep to draw lines between the entries in the body of the heatmap

ADD REPLYlink written 5.1 years ago by russhh4.8k
2
gravatar for arno.guille
5.1 years ago by
arno.guille400
France
arno.guille400 wrote:

Try this 

 

n1 <- read.table(file="test.txt", header=T)
n1 <- data.matrix(n1)
col = heat.colors(256)
col = col[order(col,decreasing=T)]
heatmap.2(n1, trace="none",col=col)
ADD COMMENTlink modified 5.1 years ago • written 5.1 years ago by arno.guille400

Hi Irsan and arno.guille, your comments are very helpful,but I still have problem: the picture color becomes white and red!  I want it to be between yellow and red.

Sorry for my second unclear question.  Each value is presented by a color cell in R heatmap, but by default the cell does not have boundary lines .  I want to  add white (or gray) boundary lines, and ideally I can adjust the width of the boundary line. THANKS a lot!

ADD REPLYlink modified 5.1 years ago • written 5.1 years ago by biolab1.1k
1

with the function colorRampPalette you can create your own gradient color.

For example :

col=colorRampPalette(c("yellow","red"))
col(100)

 

For the second question, i don't think it's possible to do it with R

ADD REPLYlink modified 5.1 years ago • written 5.1 years ago by arno.guille400
1

You can't create the boundary lines with R, but you can use the rowsep or colsep to create white/grey lines between the cells.

This is just a vector of numeric values, which says how width the gap between two columns or rows should be.
 

# block sepration
           colsep,
           rowsep,
           sepcolor="white",
           sepwidth=c(0.05,0.05),

 

colsep, rowsep, sepcolor

(optional) vector of integers indicating which columns or rows should be separated from the preceding columns or rows by a narrow space of color sepcolor.

sepwidth

(optional) Vector of length 2 giving the width (colsep) or height (rowsep) the separator box drawn by colsep and rowsep as a function of the width (colsep) or height (rowsep) of a cell. Defaults to c(0.05, 0.05)
ADD REPLYlink written 5.1 years ago by Assa Yeroslaviz1.2k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1718 users visited in the last hour